As a developers, every day we are working coding many APIs.
But, what about design? Sometimes due to the project schedule, too much requirements and even the lack of knowledge about what is REST
; developers forget about the design of API.
Months ago I was surfing on the internet, don’t remember where but I read:
REST
is more than work withxml
orjson
.
And that’s true. So, I researched more about REST and learned lot of things.
What RAML is?
RESTful API Modeling Language
allow us to design, describe, define the API. It’s human readable and it is visible to everyone.
That’s pretty cool, we can design the API and document as well.
Security
RAML
supports authentication:
- Basic authentication
- Digest authentication
- Oauth 1.0
- Oauth 2.0
Book Store API
In the example below, I have designed a Books Store API working my favourite book list. The API allow me to Create, Read, Update and Delete books. A simple CRUD operation which is represents by HTTP methods.
OPERATION | HTTP METHODS |
---|---|
CREATE | POST |
READ | GET |
UPDATE | PUT |
DELETE | DELETE |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 |
|
As you can see, the Book Store API have five services:
- GET http://localhost:8081/api/books
- POST http://localhost:8081/api/books
- GET http://localhost:8081/api/books/{bookId}
- PUT http://localhost:8081/api/books/{bookId}
- DELETE http://localhost:8081/api/books/{bookId}
Learn more about HTTP Status
Platforms and Tools
- Mulesoft provides an API Platform and APIkit.
- raml2html, transform raml file to html.
- jaxrs-to-raml, generate raml file to existing JAX-RS services. It has been updated today, JAX-RS 2.0 Asynchronous Responses is now supported!!!
There are more RAML projects here.
Resources
There are a lot of resources about REST, how to write a good API, some of them are: