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

Designing a RESTful API to interact with a simple SQLite database

Imagine that we have to start working on a mobile App that has to interact with a RESTful API to perform CRUD operations with games. We don't want to spend time choosing and configuring the most appropriate ORM ( Object-Relational Mapping); we just want to finish the RESTful API as soon as possible to start interacting with it via our mobile App. We really want the games to persist in a database but we don't need it to be production-ready, and therefore, we can use the simplest possible relational database, as long as we don't have to spend time making complex installations or configurations.

Django REST framework, also known as DRF, will allow us to easily accomplish this task and start making HTTP requests to our first version of our RESTful Web Service. In this case, we will work with a very simple SQLite database, the default database for a new Django REST framework project.

First, we must specify the requirements for our main resource: a game. We need the following attributes or fields for a game:

  • An integer identifier
  • A name or title
  • A release date
  • A game category description, such as 3D RPG and 2D mobile arcade.
  • A bool value indicating whether the game was played at least once by a player or not

In addition, we want our database to save a timestamp with the date and time in which the game was inserted in the database.

The following table shows the HTTP verbs, the scope, and the semantics for the methods that our first version of the API must support. Each method is composed by an HTTP verb and a scope and all the methods have a well defined meaning for all games and collections.

Tip

In a RESTful API, each resource has its own unique URL. In our API, each game has its own unique URL.

主站蜘蛛池模板: 南召县| 土默特左旗| 许昌市| 白河县| 祁连县| 准格尔旗| 山阴县| 娱乐| 武胜县| 赣州市| 任丘市| 黄平县| 轮台县| 乐平市| 磴口县| 旬邑县| 灌阳县| 克东县| 华坪县| 日土县| 峡江县| 会东县| 河北省| 松溪县| 宜良县| 遂昌县| 雷波县| 武乡县| 行唐县| 东山县| 仪征市| 海安县| 长春市| 曲沃县| 桦川县| 彩票| 行唐县| 阿图什市| 平顺县| 织金县| 郑州市|