"For example, if you want to add the ability to create an article, it might be tempting to create a URI called /create_article/. This is wrong, because it conflates the object (the resource) and the action (creation)." So what URL do I use if I want to search articles? What if I want to approve articles? The simple CRUD perspective has fallen apart for me pretty quickly in practice- I need more than 6 verbs (adding H…
I've always thought that the URL to use when searching articles is the same you would use when retrieving a collection of articles, just with the search terms or filters included as parameters, ie, /articles?q=terms Approving articles could be as simple as posting TRUE to the "approved" attribute of an article, ie, /articles/1234/approved You just need to make sure that every resource that can be modified or retrieve…
Designing a RESTful Web Application
11–20 of 24 posts
Re: Designing a RESTful Web Application
#12Re: Designing a RESTful Web Application
#13"For example, if you want to add the ability to create an article, it might be tempting to create a URI called /create_article/. This is wrong, because it conflates the object (the resource) and the action (creation)." So what URL do I use if I want to search articles? What if I want to approve articles? The simple CRUD perspective has fallen apart for me pretty quickly in practice- I need more than 6 verbs (adding H…
To approve you create a new approval resource: POST to /approval with the id of the resource to approve. This creates a new resource at /approval/1
Then you can revoke the approval by DELETE /approval/1
Re: Designing a RESTful Web Application
#14I like this text for explicitly bringing this problem up.
Re: Designing a RESTful Web Application
#15"For example, if you want to add the ability to create an article, it might be tempting to create a URI called /create_article/. This is wrong, because it conflates the object (the resource) and the action (creation)." So what URL do I use if I want to search articles? What if I want to approve articles? The simple CRUD perspective has fallen apart for me pretty quickly in practice- I need more than 6 verbs (adding H…
GET /search?q=terms
> What if I want to approve articles?
POST /articles/articleID?approved=1
It's actually got potential to be very clean.
Re: Designing a RESTful Web Application
#16Re: Designing a RESTful Web Application
#17Earlier quoted context omitted.
I've always thought that the URL to use when searching articles is the same you would use when retrieving a collection of articles, just with the search terms or filters included as parameters, ie, /articles?q=terms Approving articles could be as simple as posting TRUE to the "approved" attribute of an article, ie, /articles/1234/approved You just need to make sure that every resource that can be modified or retrieve…
Or treat search as a first-class resource.
Re: Designing a RESTful Web Application
#18Semantically, xhtml can represent all of the same data structures/types as JSON: lists are UL elements, dictionaries are OL elements, numbers, strings, and booleans are really just strings in both, objects are really just dictionaries, and nulls in xhtml can be a special string as in JSON or an empty element.
In both cases, the client has to either already know about the data structure and how to navigate it, or can treat it generically. XHTML has an advantage here; every data item can be labeled with an id or class attribute to make it easier to find. You can't do that in JSON unless everything is a dictionary value.
For methods, browsers support GET and POST, and they can simulate PUT with upload controls. For DELETE, the common approach is to use POST with _method=DELETE as a parameter. That's easy to adjust in your service as the request comes in so most of your service doesn't have to know about it.
Browsers are also pretty good about sending other headers, particularly the ones that have to do with caching. That'll force you to deal with them, which is a good thing.
Ideally, you'll want to just generate a data structure internally, and use the Accept request header to determine whether to send a text/json or text/html response. That way clients that want JSON can ask for and get it, while generic clients (eg: browsers) will get something they can handle. You'll also be generating the xhtml programatically, which will help to keep it uniform and predictably structured.
Re: Designing a RESTful Web Application
#19Earlier quoted context omitted.
Or treat search as a first-class resource.
I wonder if it makes more sense to treat search as a first class method , i.e. issue an HTTP SEARCH request against a resource.
Re: Designing a RESTful Web Application
#20"For example, if you want to add the ability to create an article, it might be tempting to create a URI called /create_article/. This is wrong, because it conflates the object (the resource) and the action (creation)." So what URL do I use if I want to search articles? What if I want to approve articles? The simple CRUD perspective has fallen apart for me pretty quickly in practice- I need more than 6 verbs (adding H…
To search use the search resource. Then you have, resource: "search results containing the word 'tuesday'"; url: /search?q=tuesday To approve you create a new approval resource: POST to /approval with the id of the resource to approve. This creates a new resource at /approval/1 Then you can revoke the approval by DELETE /approval/1
The typical model is to have 'container' resources. For example, if /articles/9001 is a resource, /articles is the container. You can POST to the container to create a new resource, and you can GET the container to find out some information about it, such as the number of resources it contains and a list of them. For this part of the design I'll typically return a list of links to the first N resources in the container and a navigation link to the next N resources. That navigation link uses the same URL for the container resource, but with a query parameter that tells it which resource to start on. I'll typically also implement search/filter query parameters to allow further control over the list of resources to include in the container's representation.