Reputation: 17012
I am designing a rest api that will accept a date and return if the date is a holiday or not in boolean format. What should be the url pattern for this be?
GET <domainname>/holidays?date=<mmddyyy>
Should it be something like this or is there a better way to design the url?
Upvotes: 0
Views: 419
Reputation: 57279
Should it be something like this or is there a better way to design the url?
The machines don't care - the URI is just an identifier. Like variable names, we give them human readable spellings for our own benefit.
Which is to say, if you were to use an identifier like
/a7c63fe6-ca28-4f21-9421-c9ca3df75658?yyyymmdd
Then everything should still work.
Using application/x-www-form-urlencoded
key/value pairs is a good choice, because HTML form processors understand how to build those URI, and so they can be used/tested via web pages.
?date=<YYYY-MM-DD>
But other arrangements aren't wrong; we just have different trade offs.
/holidays/date/<mmddyyy>
That spelling allows you to interesting things with relative references.
Assuming you intend that the client creates these URI, you'll want something that is consistent with the URI Template specification.
Randal Munroe strongly encourages you to encourage date spellings consistent with ISO-8601.
Upvotes: 1