My only real exposure to the ideas of REST has been through Ruby on Rails' RESTful routing. This has suited me well for the kind of CRUD-based applications I have built with Rails, but consequently my understanding of RESTfulness is somewhat limited.
Let's say we have a finite collection of Items, each of which has a unique ID, and a number of properties, such as colour, shape, and size (which might be undefined for some Items).
Items can be used by a client for a period of time, but each Item can only be used by one client at once. Access to Items is regulated by a server. Clients can request the temporary use of certain items from a server.
Usually, clients will only be interested in getting access to a number of Items with particular properties, rather than getting access to specific Items.
When a client requests use of a number of Items, the server responds with a list of IDs corresponding to the request, or with a response that says that the requested Items are not currently available or do not exist.
A client can make the following kinds of request:
The toy example above is like a resource allocation problem I have had to deal with recently. How should I go about thinking about it RESTfully?
Learning about APIs can be challenging and daunting to new developers, but to help you keep growing and progressing in your career, Postman has crafted a new public REST API collection, where you can expand your knowledge and understanding of a variety of REST APIs. At Postman, we strive to make APIs more accessible and easy to work with.
A resource can be any information that could be named, such as a document or image, a collection of other resources, a non-virtual object, and more. Meanwhile, REST uses a resource identifier to recognize the specific resource involved in an interaction between components.
REST stands for REpresentational State Transfer. It means when a RESTful API is called, the server will transfer to the client a representation of the state of the requested resource.
The REST set of constraints will make your APIs easier to use and also easier to discover, meaning a developer who is just starting to use your APIs will have an easier time learning how to do so. REST stands for RE presentational S tate T ransfer.
The trick to understanding is to think about the problems from a focus on nouns instead of verbs.
In the rest world, the verbs are all "preset" and the nouns become infinitely flexible. In a soap or roc world, the verbs are infinitely flexible. Restrict your thinking to locking down the verbs and then see what nouns you need to solve your problem within the constraints you have.
That is exactly what darrel did in the answer above - he made up a new noun for a lock that would satisfy your constraints and then set up access to them to achieve what you wanted.
Some of your questions were search or filter related - for those think of GET against the types of resources, passing in query parameters to restrict or filter the results.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With