YARAS provides standards, guidelines and conventions for writing RESTful APIs and is intended to encourage consistency, maintainability, and consistent use of b
YARAS provides standards, guidelines and conventions for writing RESTful APIs and is intended to encourage consistency, maintainability, and consistent use of b
YARAS provides standards, guidelines and conventions for writing a RESTful API and is intended to encourage consistency, maintainability, and consistent use of best practices.
Anyone who's spent time writing or using RESTful APIs knows that one size does NOT fit all. REST leaves a tremendous gap between what REST defines and what goes into a full API.
Before I started writing my own I thought I thought I'd be able to find a great RESTful standard that I could use with a quick search or two. In my search I found lots of great APIs, lots of articles on best practices and yes - even a standard or two.
Unfortunately I didn't find anything that captured what I was looking for. What I found was that some API Standards did what I wanted and some did not. For example I very much liked the documentation for PayPal's API but disliked the use of the version in the url. However, I very much liked the way that github uses media types for versioning. The Eve framework uses Mongo DB syntax for filters (e.g. where, sorting and field inclusion). Further these examples where standards so are written in the wrong way to guide RESTful API developers. This standard this is a blend of the best of what I could find that's already out there combined with (very few) of my own ideas.
The bottom line is that nothing out there did quite what I wanted. While nothing was new - it's a combination of what some of the best APIs are doing that I think represents the best practices.
At a very high level I wanted support for these things - though there is much more below:
This document borrows heavily from these EXCELLENT sources (many more are at the end of this document):
This is a draft... there are likely many issues with this as well as a number of things I'd like to do - here are a few:
I plan on moving this standard along over time so just as with any other software project I will create branches and versions and encourage you to reference the appropriate version number if you refer to this document so people are aware of what version you speak of.
Note: the where clauses above are shown un-encoded for clarity.
APIs can support the full range of CRUD operations. Within the same API, you can have a read-only resource accessible at one endpoint, along with a fully editable resource at another endpoint. The following table shows our implementation of CRUD via REST:
Action HTTP Verb Context
Create POST Collection
Read GET, HEAD Collection/Document
Update PATCH Document
Replace PUT Document
Delete DELETE Collection/Document
As a fallback for the odd client not supporting any of these methods, the API should honor X-HTTP-Method-Override requests. For example a client not supporting the PATCH method could send a POST request with a X-HTTP-Method-Override: PATCH header. This indicates that the server should perform a PATCH, overriding the original request method.
The overall JSON response for this standard follows the HAL standard with a couple additional elements:
Part of the HAL standard:
Compatible with but not part of the HAL Standard:
At the top level every HATEAOS response looks like this (though _embedded is optional):
{
"data" : {
},
"_metadata" : {
},
"_links" : {
},
"_embedded" : {
}
}The data for every resource falls within the data element. As an API designer this where the resource model is populated and is the meat of what you'll be defining. If there is a single resource the data object represents that resource. If there is more than one resource data may be an array or map of resources.
Generally follow Google JSON Style Guide when building out JSON objects. This is because tools will tend to follow these guides.
Required Fields:
Beyond that here are some guidelines for building sensible JSON response bodies:
No open issues yet, or sync has not completed.