HTML Diff
0 added 0 removed
Original 2026-01-01
Modified 2026-02-21
1 <p>In programming, the abbreviation<a>CRUD</a>stands for four basic operations that you can perform on information: creating, reading, updating, and deleting.</p>
1 <p>In programming, the abbreviation<a>CRUD</a>stands for four basic operations that you can perform on information: creating, reading, updating, and deleting.</p>
2 <p>CRUD operations work around an entity, such as a user. To operate, they create an interface using forms or HTTP API endpoints.</p>
2 <p>CRUD operations work around an entity, such as a user. To operate, they create an interface using forms or HTTP API endpoints.</p>
3 <p>The<a>Dummy JSON</a>service provides a complete set of these operations for entities. Let's take a closer look at them.</p>
3 <p>The<a>Dummy JSON</a>service provides a complete set of these operations for entities. Let's take a closer look at them.</p>
4 <p><em>This service doesn't perform actual changes on the server for security reasons. All the operations look like they make changes, but the changes don't happen</em></p>
4 <p><em>This service doesn't perform actual changes on the server for security reasons. All the operations look like they make changes, but the changes don't happen</em></p>
5 <p>Let's consider that example:</p>
5 <p>Let's consider that example:</p>
6 <p>Here you see 1. It is the identifier for a particular user. It will change depending on which user we're working with right now. By the way, the identifier doesn't have to be a number. It depends on what the backend considers an identifier and how we create it in the database. For example, in MongoDB, the identifier consists of numbers and letters.</p>
6 <p>Here you see 1. It is the identifier for a particular user. It will change depending on which user we're working with right now. By the way, the identifier doesn't have to be a number. It depends on what the backend considers an identifier and how we create it in the database. For example, in MongoDB, the identifier consists of numbers and letters.</p>
7 <p>Note the use of HTTP methods:</p>
7 <p>Note the use of HTTP methods:</p>
8 <ul><li>GET is for fetching data</li>
8 <ul><li>GET is for fetching data</li>
9 <li>POST is for forms creating</li>
9 <li>POST is for forms creating</li>
10 <li>PATCH is for updating</li>
10 <li>PATCH is for updating</li>
11 <li>DELETE is for deleting</li>
11 <li>DELETE is for deleting</li>
12 </ul><p>The URL, however, often remains the same.</p>
12 </ul><p>The URL, however, often remains the same.</p>
13 <p>Using the correct methods is handy when it comes to working with APIs. Any HTTP requests around the Internet are handled by web servers and intermediate proxies on the way to the server. Both the web server and proxies are aware of the different features of HTTP and can perform various optimizations depending on request parameters, like caching the result.</p>
13 <p>Using the correct methods is handy when it comes to working with APIs. Any HTTP requests around the Internet are handled by web servers and intermediate proxies on the way to the server. Both the web server and proxies are aware of the different features of HTTP and can perform various optimizations depending on request parameters, like caching the result.</p>
14 <p><strong>Caching</strong>is a technique that allows a web server or proxy to save a response from a server and return it for future requests without contacting the server itself. Caching speeds up access to resources and takes the load off servers. For example, we can cache GET to speed up access because GET never changes the data, i.e., it's safe. The POST, PATCH, and DELETE methods cannot be cached. They have to come to the server because they make changes.</p>
14 <p><strong>Caching</strong>is a technique that allows a web server or proxy to save a response from a server and return it for future requests without contacting the server itself. Caching speeds up access to resources and takes the load off servers. For example, we can cache GET to speed up access because GET never changes the data, i.e., it's safe. The POST, PATCH, and DELETE methods cannot be cached. They have to come to the server because they make changes.</p>
15 <h2>Adding a user</h2>
15 <h2>Adding a user</h2>
16 <p>According to the<a>documentation</a>, we can add a user by sending a POST request to the endpoint https://dummyjson.com/users/add. We can send data in different formats, such as HTML or JSON.</p>
16 <p>According to the<a>documentation</a>, we can add a user by sending a POST request to the endpoint https://dummyjson.com/users/add. We can send data in different formats, such as HTML or JSON.</p>
17 <p>To use JSON, you need to perform two steps while preparing a query:</p>
17 <p>To use JSON, you need to perform two steps while preparing a query:</p>
18 <ul><li>Enter a Content-Type header with the value application/json</li>
18 <ul><li>Enter a Content-Type header with the value application/json</li>
19 <li>Convert the data to JSON</li>
19 <li>Convert the data to JSON</li>
20 </ul><p>The result is that the query will look like this:</p>
20 </ul><p>The result is that the query will look like this:</p>
21 <p>What are the possible responses from the server:</p>
21 <p>What are the possible responses from the server:</p>
22 <ul><li>201 - resource successfully created</li>
22 <ul><li>201 - resource successfully created</li>
23 <li>422 - validation error</li>
23 <li>422 - validation error</li>
24 <li>406 - incorrect data or wrong format</li>
24 <li>406 - incorrect data or wrong format</li>
25 </ul><p>Read more about HTTP codes<a>here</a>. Most of them can occur with any HTTP method.</p>
25 </ul><p>Read more about HTTP codes<a>here</a>. Most of them can occur with any HTTP method.</p>
26 <h2>Updating a user</h2>
26 <h2>Updating a user</h2>
27 <p>To update the user, we must send a PATCH request to the endpoint https://dummyjson.com/users/{id}. You can update any set of parameters, not necessarily all at once:</p>
27 <p>To update the user, we must send a PATCH request to the endpoint https://dummyjson.com/users/{id}. You can update any set of parameters, not necessarily all at once:</p>
28 <p>If everything goes well, there are two possible responses:</p>
28 <p>If everything goes well, there are two possible responses:</p>
29 <ul><li>Code 200 and some data, such as JSON with updated resource data</li>
29 <ul><li>Code 200 and some data, such as JSON with updated resource data</li>
30 <li>Code 204, if there's no response body</li>
30 <li>Code 204, if there's no response body</li>
31 </ul><h2>Deleting a user</h2>
31 </ul><h2>Deleting a user</h2>
32 <p>To delete a user, we must send a DELETE request to the endpoint https://dummyjson.com/users/{id}. There is no request body in this case because everything is clear from the request address:</p>
32 <p>To delete a user, we must send a DELETE request to the endpoint https://dummyjson.com/users/{id}. There is no request body in this case because everything is clear from the request address:</p>
33 <p>If everything goes well, there are two possible responses:</p>
33 <p>If everything goes well, there are two possible responses:</p>
34 <ul><li>Code 200 and some data</li>
34 <ul><li>Code 200 and some data</li>
35 <li>Code 204 and an empty response body</li>
35 <li>Code 204 and an empty response body</li>
36 </ul><h2>Idempotency</h2>
36 </ul><h2>Idempotency</h2>
37 <p>When working with APIs, request idempotency is crucial. It is a property that tells you how safe it is to repeat an HTTP call. An idempotent query gives the same result regardless of the number of calls made.</p>
37 <p>When working with APIs, request idempotency is crucial. It is a property that tells you how safe it is to repeat an HTTP call. An idempotent query gives the same result regardless of the number of calls made.</p>
38 <p>Take the /users endpoint. It returns a list of users and does not change anything on the server. Each new call to this endpoint returns an identical list of users. Therefore, it's idempotent. The user list may change if it's changed somewhere else, but even that doesn't make a GET request to /users not idempotent. The main thing is that the query itself does not change anything.</p>
38 <p>Take the /users endpoint. It returns a list of users and does not change anything on the server. Each new call to this endpoint returns an identical list of users. Therefore, it's idempotent. The user list may change if it's changed somewhere else, but even that doesn't make a GET request to /users not idempotent. The main thing is that the query itself does not change anything.</p>
39 <p>The POST request, on the other hand, is not idempotent. Each call to /users/add adds a new user, albeit with the same data. Or it returns an error if, for example, the server has added a uniqueness check for some data. That's why when you send a form and refresh the page using F5, the browser always asks if you want to make this request again.</p>
39 <p>The POST request, on the other hand, is not idempotent. Each call to /users/add adds a new user, albeit with the same data. Or it returns an error if, for example, the server has added a uniqueness check for some data. That's why when you send a form and refresh the page using F5, the browser always asks if you want to make this request again.</p>
40 <p>PATCH is conventionally also not idempotent, but it's often made idempotent in practice. But browsers or web servers can no longer rely on this because they don't know the specifics of particular applications.</p>
40 <p>PATCH is conventionally also not idempotent, but it's often made idempotent in practice. But browsers or web servers can no longer rely on this because they don't know the specifics of particular applications.</p>
41 <p>The most curious thing is that DELETE is idempotent by convention. It means that deleting an already deleted resource again should return a 204 code, according to the HTTP specification. In practice, many programmers don't know about it, so usually, a second deletion leads to a 404 error.</p>
41 <p>The most curious thing is that DELETE is idempotent by convention. It means that deleting an already deleted resource again should return a 204 code, according to the HTTP specification. In practice, many programmers don't know about it, so usually, a second deletion leads to a 404 error.</p>
42 <p>Idempotency is fixed for HTTP methods in its specification, but the extent to which HTTP APIs comply with these rules depends on the programmers.</p>
42 <p>Idempotency is fixed for HTTP methods in its specification, but the extent to which HTTP APIs comply with these rules depends on the programmers.</p>