- I am about to say many stupid stuff, mostly based on experience
Application programming interface
An API expresses a software component in terms of its operations, inputs, outputs, and underlying types. An API defines functionalities that are independent of their respective implementations, which allows definitions and implementations to vary without compromising the interface
- API: an API is a set of
Endopints
that stablish a contract of the wayClients
can comunicate with the system exposing the API - Endpoint: a single IN/Out operation
- iPhone/Android/JS apps
- consistent
- "self-documented"
- stable
- friendly regarding breaking changes
When building APIs in a Ruby on Rails world, there are some default choices and convetions to consider
- HTTP 1.1
- JSON
- Rails conventions
- REST*
* Rails itself is not really restful, it lacks hateoas
In essence, an endpoint is a simple Input / Output operation, then is very easy to test, given endpoints being stateless under REST
- http verb
- url
- headers
- body/params
- status code
- headers
- body
- HTTP Auth: when i don't need to know who is logging in
- Token Based Auth: when i want to identify the user and authenticate him
Authorization
header- JWT tokens FTW!
{
"error": {
"status": 422,
"id": "unprocessable_entity",
"message": "The given params are not valid",
"documentation_url": "https://api.com/docs",
"validations": {
"title": [
"can't be blank"
]
}
}
}
the error id
can potentially be a custom kind of error id, not necessarily matching
the status code, as an "explanation" of this particual error case
- create a proposal
- make a PR out of it!
- discuss and agree it
- mock it
- profit
-
request headers
- Content-Type
- Accept
- Accept-Language
- Authorization
- If-None-Match
- User-Agent
-
response headers
- ETag
- Content-Type
- 2XX - Success
- 3XX - Redirection
- 4XX - Client error
- 5XX - Server error
https://github.com/interagent/http-api-design https://github.com/hyperoslo/api-playbook
- logging
- error tracking
- uptime checking
- event tracking
gem 'devise'
gem 'doorkeeper'
gem 'doorkeeper-jwt'
gem 'cancancan'
- https://github.com/doorkeeper-gem/doorkeeper
- https://github.com/chriswarren/doorkeeper-jwt
Accept
header, rather than URL- version:
- routes
- controllers
- views
- a new version of the enpoint, defaults to the previous version
gem 'api-versions'
Other alternatives:
- https://github.com/bploetz/versionist
- https://github.com/bwillis/versioncake
- https://github.com/EDMC/api-versions
gem 'rspec_api_documentation'
gem 'apitome'