官术网_书友最值得收藏!

Understanding the tasks performed by each HTTP method

The following table shows the HTTP verbs, the scope, and the semantics for the methods that our new API must support. Each method is composed by an HTTP verb and a scope and all the methods have well-defined meanings for all the resources and collections.

We want our API to be able to update a single field for an existing resource, and therefore, we will provide an implementation for the PATCH method. The PUT method is meant to replace an entire resource and the PATCH method is meant to apply a delta to an existing resource. In addition, our RESTful API must support the OPTIONS method for all the resources and collection of resources.

We don't want to spend time choosing and configuring the most appropriate ORM, as seen in our previous API; we just want to finish the RESTful API as soon as possible to start interacting with it. We will use all the features and reusable elements included in Django REST Framework to make it easy to build our API. We will work with a PostgreSQL database. However, in case you don't want to spend time installing PostgreSQL, you can skip the changes we make in Django REST Framework ORM configuration and continue working with the default SQLite database.

In the preceding table, we have a huge number of methods and scopes. The following list enumerates the URIs for each scope mentioned in the table, where {id} has to be replaced with the numeric id or the primary key of the resource:

  • Collection of game categories: /game-categories/
  • Game category: /game-category/{id}/
  • Collection of games: /games/
  • Game: /game/{id}/
  • Collection of players: /players/
  • Player: /player/{id}/
  • Collection of scores: /player-scores/
  • Score: /player-score/{id}/

Let's consider that http://localhost:8000/ is the URL for the API running on the Django development server. We have to compose and send an HTTP request with the following HTTP verb (GET) and request URL (http://localhost:8000/game-categories/) to retrieve all the stored game categories in the collection:

GET http://localhost:8000/game-categories/ 
主站蜘蛛池模板: 英山县| 阿克| 麟游县| 筠连县| 新丰县| 邳州市| 大港区| 乐清市| 遵义市| 华宁县| 小金县| 柞水县| 普洱| 涡阳县| 东安县| 石景山区| 延寿县| 墨玉县| 沾化县| 西昌市| 海晏县| 双城市| 西丰县| 兴山县| 钟山县| 麦盖提县| 新余市| 衡阳市| 宁强县| 德令哈市| 西贡区| 正宁县| 台中市| 靖边县| 偃师市| 东乌珠穆沁旗| 新干县| 曲沃县| 嘉定区| 左云县| 称多县|