Skip to content

Latest commit

 

History

History
113 lines (76 loc) · 2.83 KB

apireference.md

File metadata and controls

113 lines (76 loc) · 2.83 KB

API Reference

Let us talk about the REST API specification (yawn)

HTTP/1.1 Specification: https://tools.ietf.org/html/rfc2616

Theory

Base URI and Paths/Endpoints/Resources

Base URI: https://api.thecatapi.com/v1

and

Paths/Endpoints/Resources: /images or /images/:image_id

Methods

Most commonly used:

  • GET
  • POST
  • PUT
  • DELETE

Make a GET call to https://api.thecatapi.com/v1/images/search

Query params

So called optional parameters. Its about limiting and specifying response.

Make a GET call to https://api.thecatapi.com/v1/images/search?size=small&limit=5

Headers

Response and request.

Make again a GET call to https://api.thecatapi.com/v1/images/search Notice all the different headers, content type or length.

Body/Payload

It is not only when you POST but also whey you GET a response.

Make a POST call to https://api.thecatapi.com/v1/favourites with Content-Type: application/json

{
	"image_id": "4m6"
}

Check also the response body. Then DELETE what you just created.

Schemas and Mixins

It is all about the body

Schema says what are the main service readable attributes: http://jsonschema.net/ Mixins say that you can basically put whatever you want.

  • Useful for validation
  • Gives a good overview of what data have to be provided

Make a POST call with Content-Type: application/json

{
	"image_ids": "4m6"
}

Notice the validation error message in response.

Response body and codes

All listed here: https://httpstatuses.com/

  • 200
  • 400
  • 500

Make again a GET call to https://api.thecatapi.com/v1/favourites Make again a POST call with Content-Type: application/json

{
	"image_id": "4m6"
}

Document using Swagger aka OpenAPI Spec

Document using RAML

RAML spec: https://github.com/raml-org/raml-spec/blob/master/versions/raml-08/raml-08.md Go to https://github.com/derberg/minerva/blob/master/service/api/api.raml

Develop with approach API First then you get:

Write it using:

Alternatives:

  • API Blueprint
  • Apiary
  • Swagger