<?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: Erkin Yılmaz</title>
    <description>The latest articles on DEV Community by Erkin Yılmaz (@erkinyilmz).</description>
    <link>https://dev.to/erkinyilmz</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%2F853549%2Ff6db6a3e-d8f8-4930-bd8a-90731f545c0b.jpg</url>
      <title>DEV Community: Erkin Yılmaz</title>
      <link>https://dev.to/erkinyilmz</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/erkinyilmz"/>
    <language>en</language>
    <item>
      <title>Backend Basics: RESTful API (API, REST, Methods, JSON, Examples)</title>
      <dc:creator>Erkin Yılmaz</dc:creator>
      <pubDate>Tue, 10 May 2022 10:39:03 +0000</pubDate>
      <link>https://dev.to/altogic/backend-basics-restful-api-api-rest-methods-json-examples-25nj</link>
      <guid>https://dev.to/altogic/backend-basics-restful-api-api-rest-methods-json-examples-25nj</guid>
      <description>&lt;p&gt;As you probably know, a typical modern application consists of 2 main parts: Frontend and Backend.&lt;/p&gt;

&lt;p&gt;If you want to create a web or mobile app, you need to have at least a basic understanding of REST API which is commonly used on backend development.&lt;/p&gt;

&lt;p&gt;Todays technology enables developers to create complex backend apps using these simple concepts in no time by using BaaS platforms like &lt;a href="https://altogic.com" rel="noopener noreferrer"&gt;Altogic.&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  RESTful API
&lt;/h2&gt;

&lt;p&gt;Let’s break it down and understand the REST &amp;amp; API terms.&lt;/p&gt;

&lt;h3&gt;
  
  
  Italian Restaurant Metaphor
&lt;/h3&gt;

&lt;p&gt;Let’s say you are trying to find nearby Italian restaurants on your favorite restaurant review app. You open up your mobile app, type “Italian” into a search field, hit enter, and you see a list of restaurants near your location.&lt;/p&gt;

&lt;p&gt;A REST API works similarly. You request something, and you get a list of results back from the service you are requesting.&lt;/p&gt;

&lt;h3&gt;
  
  
  What is API?
&lt;/h3&gt;

&lt;p&gt;An API is an Application Programming Interface. It is a set of rules that allow applications to talk to each other. The developer creates the API on the server and allows the client to talk to it.&lt;/p&gt;

&lt;p&gt;In our Italian restaurant example, the server is the application running in the cloud, and the client is the mobile app you use to search for Italian restaurants.&lt;/p&gt;

&lt;h3&gt;
  
  
  What is REST?
&lt;/h3&gt;

&lt;p&gt;REST determines what the API looks like. It stands for “Representational State Transfer,” and it is a set of rules that developers follow when they create their API. In the above example, the search functionality is an API resource exposed by REST.&lt;/p&gt;

&lt;h3&gt;
  
  
  Methods
&lt;/h3&gt;

&lt;p&gt;In RESTful API, the client and server communicate using the HTTP protocol. The client sends a request to the server, and the server processes this request and sends back a response in return.&lt;/p&gt;

&lt;p&gt;Here is the HTTP methods that are commonly used in RESTful APIs:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1. GET&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;This request is used to get a resource from a server. If you perform a GET request, the server looks for the data you requested and sends it back to you. In other words, a GET request performs a READ operation. This is the default request method.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2. POST&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;This request is used to create a new resource or perform an action on a server. If you perform a POST request, the server creates a new entry in the database or performs an action and tells you whether the creation is successful or returns the action results according to your service design.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;3. PUT / PATCH&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Primarily used for updating a resource on a server. For example, if you perform a PUT/PATCH request, the server updates an entry in the database and tells you whether the update is successful. In other words, a PUT/PATCH request performs an UPDATE operation.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;4. DELETE&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;This request is used to delete a resource from a server. If you perform a DELETE request, the server deletes an entry in the database and tells you whether the deletion is successful. In other words, a DELETE request performs a DELETE operation.&lt;/p&gt;

&lt;h2&gt;
  
  
  Okay, I got it. Can you show me an example usage of RESTful API in an app?
&lt;/h2&gt;

&lt;p&gt;As I told you, todays technology enables developers to create complex backend apps with these simple concepts in no time by using BaaS platforms.&lt;/p&gt;

&lt;p&gt;Let’s see an example with Altogic where we use RESTful API to create our backend app:&lt;/p&gt;

&lt;p&gt;1.Create your database models&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F5412%2F1%2AjmZ9bnjfEaudQX6dkbvKcw.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F5412%2F1%2AjmZ9bnjfEaudQX6dkbvKcw.png" alt="Models tab of Altogic Designer"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;2.Define your business logic (services)&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F5812%2F1%2ALkWL0i9bFbKkjg9Ne_iTlg.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F5812%2F1%2ALkWL0i9bFbKkjg9Ne_iTlg.png" alt="Defining a service in Altogic Designer"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;3.Create your &lt;strong&gt;RESTful&lt;/strong&gt; Endpoints and associate them with your services&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F3836%2F1%2Ab9JEk_mR-BU3jOfeo2wdjA.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F3836%2F1%2Ab9JEk_mR-BU3jOfeo2wdjA.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In this case, when a POST request is sent to the path “&lt;strong&gt;/posts/{postId}/comments&lt;/strong&gt;” (3rd photo), it will trigger the “Add comment to a post service” (2nd photo) which creates a comment object under “comments” model on our database (1st photo) with the input given.&lt;/p&gt;

&lt;p&gt;This is the logic behind your backend apps. You can create complex backend apps and connect them to your frontend using Altogic client library with ease.&lt;/p&gt;

&lt;h3&gt;
  
  
  What is JSON?
&lt;/h3&gt;

&lt;p&gt;JSON (JavaScript Object Notation) is a lightweight data-interchange format. It is easy for humans to read and write.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2160%2F0%2AdYnaVrfuE-CcsHJE.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2160%2F0%2AdYnaVrfuE-CcsHJE.jpg"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;It is mainly used to store data in document databases and transport data between different applications, primarily between a server and web applications.&lt;/p&gt;

&lt;p&gt;JSON is also frequently used in &lt;strong&gt;RESTFul APIs&lt;/strong&gt; to provide data in request and response body. Below is an example JSON document summarizing a menu of a restaurant.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F3436%2F1%2AaXuwNK7ZRq1D3sszWvxeDQ.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F3436%2F1%2AaXuwNK7ZRq1D3sszWvxeDQ.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;JSON supports the following two data structures;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Collection of name/value pairs&lt;/strong&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;An ordered list of values&lt;/strong&gt; − It includes arrays, lists, or sequences, etc.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;A name/value pair consists of a field name (in double quotes), followed by a colon, followed by a value. So in the below example, the name is “firstName”, and the value is “John”.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Example:&lt;/strong&gt; “firstName”: “John”&lt;/p&gt;

&lt;p&gt;You need to put text values between double-quotes. For numbers, boolean values, or null values, you &lt;strong&gt;do not&lt;/strong&gt; need double quotes.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Example:&lt;/strong&gt; “age”: 24&lt;/p&gt;

&lt;p&gt;In JSON, values must be one of the following data types:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;String&lt;/strong&gt; — Strings in JSON must be written in double quotes&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Number&lt;/strong&gt; — Numbers in JSON must be an integer or a floating-point&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Object&lt;/strong&gt; (JSON object) — Values in JSON can be objects. However, objects as values in JSON must follow the same rules as JSON objects.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Array&lt;/strong&gt; — Values in JSON can be arrays. Array values are provided between []&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Boolean&lt;/strong&gt; — Either true or false value&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Null&lt;/strong&gt; — Empty value or no value&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F5184%2F1%2AC8ycG_9wgvqGvq4Exa8gaA.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F5184%2F1%2AC8ycG_9wgvqGvq4Exa8gaA.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Example usage in Altogic Tester&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;You can send a POST request to the path “/posts” to trigger the “Create posts object” service which will create a posts object under posts model on the database with the input sent in JSON format:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F5412%2F1%2AuewQcbvM2NfaVMhy4V62BA.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F5412%2F1%2AuewQcbvM2NfaVMhy4V62BA.png" alt="Altogic Tester"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Thanks for reading! Follow &lt;a href="https://medium.com/altogic" rel="noopener noreferrer"&gt;Altogic&lt;/a&gt; for more content like this and sample full-stack apps with full resources and tutorials.&lt;/p&gt;

</description>
      <category>programming</category>
      <category>beginners</category>
      <category>tutorial</category>
      <category>codenewbie</category>
    </item>
  </channel>
</rss>
