RESTful API для
чайников — как сделать веб-сервис и
снабдить его правильным API. Инструменты:
Python, Flask.
APIs are awesome. By
following the REST guidelines, you can design a logical and powerful
web service that others can use. In this article, we built a RESTful
API using Python and Flask. The concepts can be extended to create
other more complex APIs.
…
In a RESTful API,
only two URLs are needed per resource. The first URL is for a
collection, which for the UFO sightings dataset is
/sightings/
.
The second URL is for a specific element, which in our case is
/sightings/<id>
.
When we apply the
HTTP verbs to these two resources, we get the following grid:
POST
|
GET
|
PUT
|
DELETE
|
|
/sightings/ |
Add a new sighting to the collection
|
Show all sightings
|
Update all sightings
|
Delete all sightings
|
/sightings/<id> |
(Error)
|
Show <id>
|
Update <id> if it exists; else error
|
Delete <id>
|
The grid describes
the effect each HTTP verb has on the two resources. For instance
GET
/sightings/
should return a list of all UFO sightings
while GET /sightings/<id>
should
display that specific sighting.
В статье
подробно рассмотрены начальные шаги
построения веб-сервиса поверх базы
данных.
Очень просвещающе.
Что особо полезно — статья чисто
практическая и небольшая, для пробуждения
интереса и демонстрации принципов.
Нубам — читать.
Комментариев нет:
Отправить комментарий