Question

I'm working on a REST API, and I'm looking for a way to give the client allowed values for a variable in a URI template. This is useful when the variable represents something like an enum. Currently the client gets back a collection of links as part of the JSON object that is returned to it, and I'd like to do something like this:

"Links":
[
    {
        "Title":"Search Articles",
        "HREF":"example.com/articles/search?keywords={keywords}&mode={mode|["allWords", "anyWords", "exactPhrase"]}"
    }
]

or this:

"Links":
[
    {
        "Title":"Search Articles",
        "HREF":"example.com/articles/search?keywords={keywords}&mode={mode}"
        "Fields":
        [
            {
                "Name":"keywords",
                "Type":"Text"
            },
            {
                "Name":"mode", 
                "Type":"Enum", 
                "Options":["allWords", "anyWords", "exactPhrase"]
            }
        ]
    }
]

This is the closest thing I've found to an answer, but I was hoping for something a bit more official.

I've also been looking at the IETF standards doc for URI Templates, which seems pretty official, but doesn't look like it has an answer for this problem.

Was it helpful?

Solution

It looks like I'm going to go with JSON Hyper-Schema. As suggested by this answer, you can accomplish what I'm after by using the Properties element they define.

I also looked at HAL, Collection+JSON, and Siren, but I prefer the JSON Hyper-Schema since it sticks with a collection of links, rather than coming up with something new.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top