Article: Stefan Tilkov helps you get started with REST
Despite the ubiquity of the web, many have had difficulties applying the architectural principles of the web to their systems. Representational State Transfer (REST), the architecture behind the web is quickly becoming a real alternative to be considered by architects developing distributed systems. In a recently released InfoQ article, Stefan Tilkov delves into the ways of designing systems using REST and examines the similarities and differences between classic interface-based approaches.
Read A Brief Introduction to REST.First outlining the key principles of REST, Tilkov flattens much of the learning curve of this much-debated architecture:
- Give every "thing" an ID
- Link things together
- Use standard methods
- Resources with multiple representations
- Communicate statelessly
Some of the benefits outlined include:
[A] consistent naming scheme for things [so] that you don't have to come up with your own scheme — you can rely on one that has already been defined, works pretty well on global scale and is understood by practically anybody.
As well as:
[A] uniform interface [that] enables every component that understands the HTTP application protocol to interact with your application. Examples of components that benefit from this are generic clients such as curl and wget, proxies, caches, HTTP servers, gateways, even Google/Yahoo!/MSN, and many more.
For those interested in more of the theory behind REST, Tilkov also gives the background as well as links to the definitive works on the subject.
Love the analogy
by
Peter Lacey
In a RESTful approach, an application might add a few million customer URIs to the Web; if it’s designed the same way applications have been designed in CORBA times, it’s contribution usually is a single “endpoint” — comparable to a very small door that provides entry to a universe of resource only for those who have the key.
Brilliant.
REST on .NET?
by
Ole Friis
However, I have not been able to find good .NET REST frameworks. Microsoft is doing Astoria, but that's a "let's publicise your database through the Web" thing, and besides that it requires WCF and thus .NET 3.
Does anybody know of any (preferably open-source) REST frameworks for .NET that are worth checking out?
RESTful with many parameters?
by
Tom Dyer
For example, I want a list of all the dependent/required products for a given set of products.
URI is /required_products/{43,555, .... very large set of product ids} And the resource identified is the list of required products for this set of products ids.
Seems like its GET but are there too many parameters needed to identify the resource?
Maybe a POST but a post is not safe, indempotent and is typically used to create a new resource, which the list of dependencies is not.
Perhaps a POST. But a POST is not "safe", it can have side effects, and is typically used for a resource update or for creating a new resource associated with the URI.
thanks,
very nice
by
Nikita Ivanov
Nikita Ivanov.
GridGain - Grid Computing Made Simple
Re: RESTful with many parameters?
by
Rafael de F. Ferreira
Re: RESTful with many parameters?
by
Tom Dyer
Wonder if the set of product id's aren't a resource that can be created, via POST, then it's identifier/URI can be used to GET the collection of dependent products.
Re: RESTful with many parameters?
by
lipman li
Re: RESTful with many parameters?
by
Kirstan Vandersluis
I'd have to agree with Tom Dyer that the approach of stuffing an arbitrarily large list into the query string seems awkward. I think this situation fits Stefan's "exception criteria" from his article:
"...there are often reasons why one would violate a REST constraint, simply because every constraint induces some trade-off that might not be acceptable in a particular situation"
I certainly don't claim to be a REST expert, but in my opinion, I'd say a POST would be a better approach in this case.
Representations
by
Jim Standley
Is it ok to put representation on the URL?
I have done this recently:
/Repo/Element/101 <- returns HTML
/Repo/Element/101?json <- returns JSON
/Repo/Element/101?edit <- returns an edit page
Re: RESTful with many parameters?
by
Tom Dyer
Also, I probably wouldn't get the caching benefits of GET because the same URI from this large set of URI's wouldn't be accessed that often. The resource would mostly likely not be a good caching canidate.
This is probably taking this to the absurd but can one use an executable artifact,( proc, code block, SQL select,...), as part of URI. The result of executing the block on the Resource server would be used to identify the resource.
Re: Representations
by
Tom Dyer
"/Repo/Element/101?edit <- returns an edit page" is similar to the URI used in Rails for a form that will be filled in to update a resource.
Would be /Repo/Element/101/edit in rails.
Re: REST on .NET?
by
Stefan Tilkov
www.infoq.com/news/2007/05/wcf-web-programming-...
and
www.infoq.com/news/2007/10/mindtouch-dream
HTH,
Stefan
Re: RESTful with many parameters?
by
Stephan Schlöpke
It is very similar with searching something with multiple parameters. In such a case it would be much easier to create a search resource and once created do a get on the created resource. And when done just send a delete to the created query resource.
There are multiple ways to solve this. However I think doing a GET on an URI and building the URI like ./something/{10,20,40 ...} on the client seems not right. It would require the client to have a detail knowledge of building the URIs while normaly the client should only follow links provided by the service.
Very nice articel stephan btw :-)
c# Interface analogy
by
Maximilian Schulz
Re: RESTful with many parameters?
by
Kirstan Vandersluis
Re: RESTful with many parameters?
by
Stephan Schlöpke
Resource graph traversal is not the same as state transition
by
Ganesh Prasad
You said:
> There is an even more important aspect to the hypermedia principle — the “state” part of the application. In short, the fact that the server (or service provider, if you prefer) provides a set of links to the client (the service consumer) enables the client *to move the application from one state to the next by following a link*.
When you say the client "moves the application from one state to the next", I understand that to mean that updates are taking place. But if the client is merely traversing links (using a sequence of GETs, for example), then the application's state has not changed at all. What has changed is the client's view or representation of the application. The client has merely changed its perspective of the application's state and is looking at it from a different "angle", so to speak. In other words, the client is traversing the resource graph, which is a hyperlinked set of URIs representing resources.
We need to make a clear distinction between State Transitions (which most people would expect to only occur on updates), and mere link traversals, which change the client's view (representation) of the application but not its state.
If the HATEAOS model means link traversal when it talks about state transitions, then we really need to clean up the terminology, because it needlessly confuses non-RESTafarians.
Regards,
Ganesh
Re: Resource graph traversal is not the same as state transition
by
Stephan Schlöpke
I think that this is a real state transition and I would say that it conforms to REST.
Re: RESTful with many parameters?
by
Kirstan Vandersluis
Re: RESTful with many parameters?
by
Stephan Schlöpke
It is like in real life. I have a guy in my office called Archie. He is responsible to gain documents from the libray whenever someone needs it. Once I have a request for a couple of documents I hand him a list what to get. Now I can just wait until he got everything in order to take it with me. Or I go back into my office waiting for an email that he has gathered all my documents for me to pick up.
In a service designed like that I create a list which is my query request. I do a PUT to archie so he has the newly created list. The receipt I get is an URI where I can get my documents once they are collected. In the normal case they are instantly available so I just do a GET on the resource and have my result. In various situations a backend needs more time to gather the documents together which may take a couple of minutes. This gives me as a client the option to inform the user that his request is beeing processed. Once the request is processed the user can see the result. Or if it is a real long request a mail is send to the user with the URI link where to get the result.
Since Archie wants his documents back he keeps the list until I am done with the documents. Once I am done I return the documents and get the list back or the list gets destroyed. This is where the client puts the DELETE to the result. Once he or she is done with it.
The good thing in it is that if you execute the query and stores the result it is totally independend from someone deleting or adding entries to the database. Those the result I see dosnt change while I am working with it. This can be of benefit especially when you do a search. If you send the link result to another person he or she can open it and the 4th entry is the same you saw. In some cases it might be better to store the query and the first get removes it. This however is not REST conform I think since the GET I can only execute once.
Executing a DELETE with the option of a timeout and a clean up task is I think the best way to go. In such a case the client has the chance to work with the result resource as long as he wants without having to store it. Also this way it is easy to cache such a resource while with POST you cannot cache the resource in a proxy since the proxy dosn't know in what relationship the posted content to the result is.
Re: Resource graph traversal is not the same as state transition
by
Stefan Tilkov
When you say the client "moves the application from one state to the next", I understand that to mean that updates are taking place. But if the client is merely traversing links (using a sequence of GETs, for example), then the application's state has not changed at all.
There is resource state and application state, and I agree the traversal of a link by the client via GET does not change the resource state. But it changes the application state, as the client is now "looking at" or "holding on to" a different representation which includes different links than the one before. Application state is thus kept on the client (which means the server doesn't care about it). But the representations sent from the server to the client "drives" it because they contain or do not contain links to specific other resources.
"Hypermedia as the engine of application state" is both the least understood and the most powerful aspect of REST, which is why we have an article just about this coming up soon.
What when REST semantics are not enough?
by
Gael Fraiteur
What is we want to have a richer state diagram? Take the example of an order, how to represent the transition from the state "booked" to "shipped" (this is a parameterless transition). And how to represent the transition to the state "cancelled", when we want to add the reason cancellation (transition with one parameter).
Object-oriented methologies have learned us how to deal with these situations using procedures/methods, but what would be the right approach using REST?
Re: RESTful with many parameters?
by
Ally Kendall
Re: What when REST semantics are not enough?
by
Ally Kendall
Re: What when REST semantics are not enough?
by
Stefan Tilkov
The mapping to CRUD is not 1:1 -- a POST can create new resources, or simply process something and return a result. In case a POST is used to create a new resource, the server chooses the URI. A PUT can be used when the URI of the resource one wants to affect is known -- it will either create or update a resource there.
Re: Love the analogy
by
Mike Glendinning
In fact this is one of the interesting tensions in the design of web-based hypermedia applications: The more we make data accessible through URIs and hyperlinks, the harder it becomes to secure and control access. This problem is exacerbated by the crude security framework of HTTP.
In the world of "enterprise applications" the norm has been for years to design systems that strictly control access to data. This is in line with the design and operation of our organisations, but contrasts markedly with the web where the goal has always been to *provide* access to data. It has also lead to a whole new industry for enterprise data warehousing and business intelligence solutions that "unlock" hidden data.
If REST is to "take over" for enterprise applications, I suggest it's going to have to address issues of data security much more seriously. The long term effects on our enterprise architecture might be quite interesting, nonetheless.
Re: Resource graph traversal is not the same as state transition
by
Ganesh Prasad
There is resource state and application state [...]
Ah, that explains everything! In my terminology, there's "client state" and "application state". You call them "application state" and "resource state". Fair enough!
This ties in neatly with our model SOFEA (Service-Oriented Front-End Architecture), where client state is managed on the client, and a controller on the client side interacts with services (either SOAP or REST) to drive what we call "Presentation Flow". Obviously, client state and Presentation Flow are constrained by the representations that the service tier exposes.
I think it's important to clarify that SOAP-based Web Services also expose *representations* of behaviour, because these do not simply mirror methods on Domain Objects. Unlike with REST-based "services", client state is not directly constrained by SOAP-based web services. Because of its nature as a verb-oriented view of a domain (rather than a noun-oriented view that is REST), either a whole process has to be encapsulated in a single operation (implemented by WS-BPEL) for the client to consume, or the client has to define a bespoke process using the set of services available. This is not necessarily a disadvantage. It's just a different model.
Regards,
Ganesh
Architecture of resources ?
by
Vladimir Vacula
- "/orders" and "/orders/{id}"
- "/customers" and "/customers/{id}"
- "/customers/{id}/orders"
what if i don't want to categorize object in URI-name of resources. What if "id" means just a document without identification, if document is an order or customer card?
Let's say i have resources :
- "/document/{id}" (which implement GET of details and POST of new documents)
- "/search" (which returns list and implement POST of restricting conditions i.e. "category:customer" or more complex "category:customer, category_id:123, relation:orders" )
Is it better to use categories in URI of resources (like "/orders") instead of creating general resources (like "/search")? Is there any recommendation which way is better and why? And finally, what if "/orders" returns really huge list? In "/search" i could implement condition i.e. "last:10", "max_date:2006-12-31". How to handle this issue in case i use resource "/orders" ?
Thanks
Re: Architecture of resources ?
by
Stefan Tilkov
First of all, the characters that make up a URI are much less important than one may think. But anway, I prefer to give resources meaningful names -- but this is just a design decision. Your document/{id} example would mean that a POST to it would be handled the same way, regardless of whether it's an order or customer, unless you switch on the content type. If handling both similarly -- e.g. if you just want to store a new document without looking at its contents -- is what you want, this seems perfectly fine.
I suggest to implement searches as GETs, not POSTs -- it's useful to be able to link to a search result, and it's a meaningful resource in itself -- "the list of all customers named Smith" qualifies as a resource from my POV.
Regarding the large lists, one way is to redirect a request to /orders to /orders?offset=0&count=10 and include a link to /orders?offset=10&count=10 -- i.e., the indivual pages become resources in themselves.
HTH,
Stefan
Re: Love the analogy
by
Felipe Nascimento
Do you suggest any material about REST security we can take a look at? If application does not hold state, how to check if some client application has the authority to access one resource? Should the client application pass in the credentials in every request? Should the RESTful application has a security service that would return a session ID that would be used by the client application in every subsequent requests?
Tks
Felipe
Re: Love the analogy
by
Stefan Tilkov
Re: RESTful with many parameters?
by
Torben Wölm
Understanding the Difference!
by
William Martinez
A RESTful HTTP approach to exposing functionality is different from RPC, Distributed Objects, and Web services; it takes some mind shift to really understand this difference
Stefan, totally agree with your claim. Most of the discussion I've had in the past relates to the confusion of all those four things. For some, Web Services are just a way to distribute object (thus a WS is an exposed object!), some others cannot imaging WS as a messaging thing: it is just an exposed method (RPC). Even more, some see on REST a simpler WS, which is not. I mean REST is much more that just WS, and WS can be implemented using REST philosophy. In fact, WS architecture's resource view is totally compatible with REST.
But to understand this, you need a "mind shift", totally true.
So IOW, this applies only to web projects. What about Windows projects?
by
Parimal Jisaheb
Re: So IOW, this applies only to web projects. What about Windows projects?
by
Stefan Tilkov
Thanks
by
Yuen Chi Lian
Cheers,
yc
Re: Architecture of resources ?
by
Mike S
On topic though totally agree with Stefan's response. Search should be exposed as GET-able URI which effectively creates unlimited list of resources which are search results. Just a slight addition to the pagination solution: I think it is better be done the same way content negotiation is, that is GET /orders would return same representation as /orders?offset=0&count=10 mentioning the latter as Location header so that the client can cache the result against the proper key. Interestingly the spec talks about Location header as the target for redirection :).
Re: What when REST semantics are not enough?
by
Mike Schinkel
Re: RESTful with many parameters?
by
Mike Schinkel
And since REST is an architecture style it could be used with a different request/response protocol and with a different uniform methods although that's just a point to clarify the though process as few people are using REST outside HTTP.
Re: Love the analogy
by
Mike Schinkel
Re: Resource graph traversal is not the same as state transition
by
Mike Schinkel
Consider REST like the physical compatibility of the plug on your computer's power cord and the electrical outlet where your computer gets its power. REST's constraint on verbs is like the plug/outlet's physical compatibility contraint. Conversely imagine having every power cord had a different type of plug; that is SOAP and all its operations! Actually if you travel a lot internationally, you already know what a nightmare of inefficiency and lack of capability that lack of conformity can produce.
Re: Architecture of resources ?
by
Mike Schinkel
In the "customer" cases you mention I'd say use "/customers" and "/customers/123/orders"
After all you can think of a URL as just a generalized query mechanism in many ways. The URL is really supposed to be an opaque string but because of web server implementations many of us have been conditioned to think of URLs are being directories and filename, even in the case of dynamic output from such as .jsp, .php, .aspx, etc. The URL really should just represent the resource whose representation it returns when dereferenced and hide how the representation is prepared on the server as the client really doesn't need to know. There is no need for a special "search" metaphor.
So for your latter "order" cases, you can use "/orders/last10" and "/orders/thru-2006-12-31" or if you just call "/orders" use paging as Stefan suggested.
Re: So IOW, this applies only to web projects. What about Windows projects?
by
Mike Schinkel
Re: So IOW, this applies only to web projects. What about Windows projects?
by
Florian Schwarz
Question about use of Cookies
by
Matthias K.
As far as I understand, the demand for stateless communication only concerns the state of resources, and not client or application state. However, the most typical use of a cookie, namely storing user preferences or session data, does for one not concern resource state, but application or client state.
Second, all required session data can be carried around in the cookie itself, and not just be stored in the server memory identifyable be a session key (as is the case with e.g. Servlets). In other words, I do not see where the mere use of cookies does not harm server scalability and reliability, if used properly.
That being said, what are your thoughts about the use of cookies in a RESTful application? Am I missing something?
Re: Question about use of Cookies
by
Stefan Tilkov
Re: Question about use of Cookies
by
m k
RESTful transaction service
by
Ian Goldsmith
I'm trying to model a service that manages checking accounts, providing some very basic capabilities. The basic resource is an account, which has an id and a set of attributes. This is easy to model:
GET <host>/accounts - will return an XML doc listing all the accounts as REST resources e.g. <host>/accounts/{accountid}.
GET <host>/accounts/{accountid} will return an XML document that lists all the attributes (for now lets assume the only attribute is the balance of the account).
What I want to create is a set of methods for "withdraw", "deposit", and "transfer". Clearly I could create these using documents for each method and POST them to the account, e.g.:
POST <host>/accounts/{accountid}
<withdraw>
<funds>{value}</funds>
</withdraw>
This doesn't seem to follow the REST contraint of using a common set of methods though. To be more RESTful, I guess I would have to PUT a new balance value to the account (at least this would be idempotent), but this gets clumsy quickly, especially for transfer, given the different authorization levels required (it's easy to see a case where I would have different authorization levels for deposit and withdraw for example).
Am I missing something obvious? Is there an easy way to implement this type of service?
Thanks in advance,
Ian</host></host></host></host>
Re: RESTful transaction service
by
Stefan Tilkov
Re: RESTful transaction service
by
Mark Little
Send large result set
by
John John
do you have any idea how to send large result sets?
request:
GET /user
server returns 10 000 records with links. It is bad practise to return all records to user. I think one of the solution can be: send to user "HTTP/1.1 303 See Other" response and to location header set domain.com/user?range=100,1000, which means that resource contains records from 100 to 1000. Does anybody have idea how to solve this problem ? It is good to solve it with 303 status code?
thx..
Do you suppose that all possible actions can be reduced to 4 verbs?
by
Mark Kamoski
Use of Accept to define required representation
by
Martin Haigh
Re: Use of Accept to define required representation
by
Stefan Tilkov
Rest URI design with URL parameters
by
Thomas Tkac
I designig REST web APP and I want to apply some operations on resource op1, op2, op3 which have one or two arguments.
I want to apply this operations in one request
sample:
GET /resource?op1=name&op1=name2&op2=aa,bb&op1=name3
in order which is in request
at first op1 then op1, op2 op1 with arguments (values)
Is this good practise or do you have any suggestion recommendation how to solve this problem?
thx
Re: UML Diagrams
by
Stefan Tilkov
Re: UML Diagrams
by
peng zhang
and www.mfrbee.com/trade/
Re: REST on .NET?
by
Vlad Bezden
If you still looking at .NET REST framework, I would recommend WCF Web API. Very nice and clean framework, the one I like most from all previous MS implementations.
REST & standard behavior
by
Dan Noonen
I'm guessing I haven't made that mind-shift that's mentioned just yet & I'm hoping some replies will help.
Educational Content
Writing Usable APIs in Practice
Giovanni Asproni May 19, 2013




Hello stranger!
You need to Register an InfoQ account or Login to post comments. But there's so much more behind being registered.Get the most out of the InfoQ experience.
Tell us what you think