<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Alonso Díaz</title>
    <description>The latest articles on DEV Community by Alonso Díaz (@aztfirespell).</description>
    <link>https://dev.to/aztfirespell</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F997469%2Fb1806f8b-978e-4f7f-a05c-99442992fecd.jpeg</url>
      <title>DEV Community: Alonso Díaz</title>
      <link>https://dev.to/aztfirespell</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/aztfirespell"/>
    <language>en</language>
    <item>
      <title>Create a minimal API with json-server</title>
      <dc:creator>Alonso Díaz</dc:creator>
      <pubDate>Thu, 05 Jan 2023 20:57:42 +0000</pubDate>
      <link>https://dev.to/aztfirespell/create-a-minimal-api-with-json-server-3753</link>
      <guid>https://dev.to/aztfirespell/create-a-minimal-api-with-json-server-3753</guid>
      <description>&lt;p&gt;** It will take you longer to read this post than to create your api &lt;em&gt;Seriously...&lt;/em&gt; **&lt;/p&gt;

&lt;p&gt;In the great world of apis there are many ways to program your own api, express, laravel, etc, but...&lt;/p&gt;

&lt;p&gt;How would you like to be able to create an api in less than a minute with all the http requests (post, put, delete, get) quickly and without so many code problems? (Yes, you could already have your api when you finish reading this post).&lt;/p&gt;

&lt;p&gt;Well json-server is for you!&lt;/p&gt;

&lt;p&gt;This can help us if we want to test a front-end in a simple way before connecting it completely with the back-end team or if you want to continue learning from the great and exciting path of the APIs (my case).&lt;/p&gt;

&lt;p&gt;You only need a json file, a universal format that you've probably come across a lot of times up to this point :)&lt;/p&gt;

&lt;p&gt;An example of a format could be with pizzas. Who in our area doesn't love them?&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{"Pizza": [
     {
       "id": 1,
       "name": "Al Tono pizza",
       "description": "lots of tuna"
     },
     {
       "id": 2,
       "name": "italian",
       "description": "mama mia!",
     }
]}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In the directory where you start working, (it doesn't matter if it's empty at this point), we execute the following command to install the package.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm install json-server
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now we create the json file (you can use the name of db.json to make it a bit more consistent with the example) and add our favorite products (I'll continue with the pizza)&lt;/p&gt;

&lt;p&gt;The following is that through npx you must execute the following command&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npx json-server --watch --port 5001 db.json
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;(If you get an error, I suggest you run the following command)&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm install -g npx
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Where the port can be the one of your preference and db.json will vary by the name of your file.&lt;/p&gt;

&lt;p&gt;Ready, you already have a functional api, and the best of all is that if you make post statements, it will remain saved in your file :)&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--a-u_QtX8--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/6wk8m0ybc75v4d1plwpz.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--a-u_QtX8--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/6wk8m0ybc75v4d1plwpz.PNG" alt="Image description" width="845" height="442"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;If you want to have an example of how to create the requests, I leave you this &lt;a href="https://documenter.getpostman.com/view/22626094/2s8Z73xqLp"&gt;documentation in postman!&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Happy code! &lt;/p&gt;

</description>
      <category>api</category>
      <category>node</category>
      <category>json</category>
      <category>tutorial</category>
    </item>
  </channel>
</rss>
