silkapp / rest

Packages for defining APIs, running them, generating client code and documentation.
http://silkapp.github.io/rest
390 stars 52 forks source link

Identifiers with Kind Cardinality greater than 1 #155

Open theNerd247 opened 6 years ago

theNerd247 commented 6 years ago

Is it possible to use an identifier such that:

data Foo = Foo Int String

.... withListing () $ named [("foo", Foo <$> singleRead <*> singleRead)]
bergmark commented 6 years ago

I'm a bit rusty on this, but I think you will need to define how to parse the segment (which is a String) into your Foo. In that sense the cardinality doesn't matter, in any case you need to provide a function String -> Foo(or similarly using Read). It's left up to you to decide when the first field ends and the second begins.

theNerd247 commented 6 years ago

So can would I be able to parse foo/10/blarg assuming the parser will take 10/blarg as the input?

hesselink commented 6 years ago

I don't think that's actually possible. What does that URL mean? Usually you'd have foo be a type of object in your API, and the next identifier would be an id to a specific foo. Where does the string come in?

If these are subproperties of some object, you can use selects in the resource for subselections on your resource, which would give you the url you want.

If these are two parts of the same identifier, the easiest thing here is to use a URL like foo/10-blarg and write a Read instance to parse that into a Foo.