ruby on rails - How do you structure a restful route with several GET constraints? -


Suppose you are working on an API, and you need a good URL. For example, depending on accounting, you might want to provide the ability to query articles with sorting.

Standard:

 Get  http://example.com/articles Php? Author = 5 & sort = desc  

I can think of a legitimate way of doing this:

  get http://example.com/ article / All / Author / 5 / Sort / Dis  

Am I right? Or is this the other thing wrong?

You're mostly right. REST is to focus on talking names with AP.

What does the name all do in this case? Do not you always expect your API to return all articles, unless you filter it?

I will create a query string parameter, next, I will create any and all filtering query string parameters. If you click on the "latest" question link, then the stack is applied, you get a query string to filter out the questions

then something like this:

Get http://example.com/aritcles/authors/5?sort=desc

but also think about what happens with each URL:

GET http://example.com/aritcles/ can return all current articles

http://example.com/aritcles/authors/ What does this URL do? Does it return to all the authors of all articles, or do all the articles return to all the authors (which is basically the same functionality of the URL.)

Obtain http: // Can return all articles of example.com / Arctical / Author / 5 / Author 5, or can he return the 5 author information?

I will change this:

http://example.com/aritcles returns all the articles return
http: / /example.com/aritcles/5 Author Returns all articles 5
HTTP://example.com/authors returns returns to all authors
http : //example.com/authors/5 returns information for author 5


Comments