Abstract
It is important to understand the role of HTTP and what it brings into the picture. The HTTP’s uniform interface relieves clients from learning fundamentally new ways of handling resources. Everything happens via URLs (these are identifiers and handles of resources at the same time) and HTTP regular methods (see the sidebar “Identifier vs. Handle” later in this chapter for more details about them).
This is a preview of subscription content, log in via an institution.
Buying options
Tax calculation will be finalised at checkout
Purchases are for personal use only
Learn about institutional subscriptionsNotes
- 1.
The OPTIONS can be used by a client to figure out the affordances regarding a particular resource. The response would be a set of HTTP methods (GET, PUT, etc.). In a Level 3 REST API the server sends this information proactively using hypermedia controls. Therefore, the client isn’t any more motivated to issue OPTIONS, nor in doubt about what is affordable with a resource (you can read more about this HTTP header at http://zacstewart.com/2012/04/14/http-options-method.html ).
- 2.
It is also possible to use the url property of the WebPage, but it is better to be consistent across your APIs. In case you need a self-link from a representation, which isn’t a WebPage per se, then you would need to come up with a new convention. Consistency is only one of the myriad quality attributes of an API (read [3] for a good overview).
- 3.
This is throwaway code, and is using static methods, which aren’t proper for an API. See the exercises at the end of this chapter for more directions on how to refactor it.
- 4.
Read more about the PathVariable annotation in the Spring documentation.
Author information
Authors and Affiliations
Rights and permissions
Copyright information
© 2016 Ervin Varga
About this chapter
Cite this chapter
Varga, E. (2016). Encoding Actions on Resources. In: Creating Maintainable APIs. Apress, Berkeley, CA. https://doi.org/10.1007/978-1-4842-2196-9_7
Download citation
DOI: https://doi.org/10.1007/978-1-4842-2196-9_7
Published:
Publisher Name: Apress, Berkeley, CA
Print ISBN: 978-1-4842-2195-2
Online ISBN: 978-1-4842-2196-9
eBook Packages: Professional and Applied ComputingProfessional and Applied Computing (R0)Apress Access Books