HTTP Methods, CRUD, & database actions

HTTP method CRUD action SQL  (Django ORM does this for you)
POST Create INSERT
GET Retrieve (Read) SELECT
PUT/PATCH Update UPDATE
DELETE Destroy DELETE

REST is a convention for structuring API data

REST (shorthand for “Representational State Transfer”) is a set of guidelines for how to represent information in an API that provides data by means of HTTP requests. We consider this data “resources.” Resources in your API are probably your models, but may be other things as well. Like models, they are usually nouns.

RESTful APIs provide endpoints to access data

You can think of an endpoint as an HTTP Method + URL + resource

Resources can be single or a collection

Resources can be single or a collection. Habits are a resource in the Habit Tracker lab project; so are daily records for tracking progress on building a habit. You probably built urls + views that included, for example:

Almost all REST APIs implement urls like the following to provide CRUD actions for single and collection resources.

HTTP method URL Description of resource
GET /habits list of all habits
POST /habits create a new habit in the db
GET /habits/1 one habit with PK 1
PUT/PATCH /habits/1 update habit with PK 1
DELETE /habits/1 delete habit with PK 1

Resources can be nested to show relationships

Related resources can be nested**.** For example, you may have shown daily records related to a single habit on a habit detail page in your Habit Tracker app.