You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: module3-crud-and-data-models/r1-schema-and-data-models/README.md
+12-9Lines changed: 12 additions & 9 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -53,44 +53,47 @@ In a REST environment, CRUD often corresponds to the HTTP methods `POST`, `GET`,
53
53
54
54
For example, imagine we are working with a system that is keeping track of meals and their corresponding prices for a restaurant. Let’s look at how we would implement CRUD operations.
55
55
56
-
-#### Create
56
+
#### Create
57
57
58
58
To create resources in a REST environment, we most commonly use the HTTP POST method. POST creates a new resource of the specified resource type.
59
59
Imagine that we are adding a new food item to the stored list of dishes for this restaurant, and the dish objects are stored in a dishes resource.
60
60
61
61
Note: Use `POST` when you want to add a child resource under resources collection.
62
62
63
-
Request:
63
+
##### Request:
64
+
64
65
`POST http://www.myrestaurant.com/api/dishes/`
65
66
66
67
We will need to send the `dish` data too.
67
-
`
68
68
69
-
-#### Read
69
+
#### Read
70
70
71
71
To read resources in a REST environment, we use the GET method. in practice, reading a resource shouldn't change any information - it should only retrieve it.
72
72
73
73
Note: technically, you can change data in a `GET` request but since we are creating a RESTful API, you shouldn't do that, and, in-general, changing data in a `GET` request would be confusing to the users of your api.
74
74
75
-
Request:
75
+
##### Request:
76
+
76
77
`GET http://www.myrestaurant.com/api/dishes/`
77
78
78
-
-#### Update
79
+
#### Update
79
80
80
81
PUT is the HTTP method used for the CRUD operation, Update.
81
82
So if the price of Avocado Toast has gone up, we should go into the database and update that information using PUT.
82
83
83
84
Note: Use `PUT` when you want to modify a singular resource which is already a part of resources collection. `PUT` replaces the resource with the data you send in its entirety.
84
85
85
-
Request:
86
+
##### Request:
87
+
86
88
`PUT http://www.myrestaurant.com/dishes/1223`
87
89
88
-
-#### Delete
90
+
#### Delete
89
91
90
92
The CRUD operation Delete corresponds to the HTTP method DELETE. It is used to remove a resource from the system.
91
93
Let’s say that the world avocado shortage has reached a critical point, and we can no longer afford to serve this modern delicacy at all. We should go into the database and delete the item that corresponds to `"Avocado Toast"`, which we know has an `id` of 1223.
0 commit comments