silkapp / rest

Packages for defining APIs, running them, generating client code and documentation.

Home Page:http://silkapp.github.io/rest

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Identifiers with Kind Cardinality greater than 1

theNerd247 opened this issue · comments

Is it possible to use an identifier such that:

data Foo = Foo Int String

.... withListing () $ named [("foo", Foo <$> singleRead <*> singleRead)]

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.

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

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.