3

What Is a RESTful API and Its Methods?

 3 years ago
source link: https://brijeshpanchal1618.medium.com/what-is-a-restful-api-and-its-methods-63195758cde2
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

What Is a RESTful API and Its Methods?

Photo by Marcos Henrique Da Silva on Toptal

In a Web Development Industry, We all are Using and Building REST APIs in our daily life. Simply, API (Application Programming Interface)means communication between applications. Now the question is What is RESTful API?

In this article, I am going to explain the basic definition of RESTful API.

Let’s say if we are trying to find videos about Elon Musk on Youtube. We open Youtube, type “Elon Musk” into a search field, hit enter, and we can see a list of videos about Elon Musk. A REST API works in a similar way. We search for something, and we get a list of results back from the service we are requesting from.

An API (application programming interface), which is a set of rules that allow programs to talk to each other. The developer creates the API on the server and allows the client to talk to it.

Definition: The RESTful API or REST (Representational State Transfer) API is an easy way to handle communication between individual systems as different as smartphones and other websites.

The RESTful API is also known as a RESTful web service whichis based on Representation State Transfer (REST) technology, an architectural design, and an interactive approach often used in the development of web services.

It is an application program interface (API) that uses HTTP requests for GET, PUT, POST, and DELETE data.

Methods to Route the Data Using RESTful API (Routing Methods/HTTP Methods)

1. GET (READ)

GET is the simplest type of HTTP request method; the one that browsers use each time you click a link or type a URL into the address bar.

This method is used to get a resource from a server. If we perform a GET request, the server looks for the data we requested and sends it back to us. In other words, a GET request performs a READ operation.

2. POST (CREATE)

POST is always for creating a resource (it does not matter if it was duplicated )

This method is used to create a new resource on a server. If we perform a POST request, the server creates a new entry in the database and tells us whether the creation is successful. In other words, a POST request performs a CREATE operation.

3. PUT (CREATE OR UPDATE)

PUT is for checking if the resource exists then update, else create a new resource

This method is used to update a resource on a server. If we perform a PUT request, the server updates an entry in the database if it exists and tells us whether the update is successful and If the resource is not available then it will create a new resource.

4. PATCH (UPDATE)

PATCH is always for update a resource

This method is used to update particular data on a server. If we perform a PATCH request, the server updates specific data on a server and If the resource is not available then it will throw an error.

5. DELETE

DELETE is easy to understand. It is used to delete a resource identified by a URL.

This method is used to delete a resource from a server. If we perform a DELETE request, the server deletes an entry in the database and tells us whether the deletion is successful. In other words, a DELETE request performs a DELETE operation.

The following image is a pictorial understanding of RESTful API.

1*6cjGAevnut9YuDmprV1Qmw.png?q=20
what-is-a-restful-api-and-its-methods-63195758cde2
(What is REST API?)

Difference Between PUT and PATCH Requests

Now Let’s understand the difference between PUT and PATCH with an example

PUT and PATCH are HTTP verbs, which are both related to updating the database.

The key difference between PUT and PATCH requests is the way the server handles the enclosed entity to modify the resource identified by the Request-URL.

Now, Let’s say we have a resource that holds the first name and last name of a person.

If we want to change the first name but not the last name then we send a request for an Update with

PUT Request

{ "firstName": "Brijesh", "lastName": "Panchal" }

With PUT request, we have to send both parameters firstName and lastName, although we are only changing the firstName.

In other words, it is mandatory to send all values again, the full payload.

PATCH Request

{ "firstName": "Brijesh" }

With the PATCH request, we only send the data which we want to update. In other words, we only send the firstName to update, no need to send the lastName.

For this reason, the PATCH request requires less bandwidth.

So, These are the main methods using in building RESTful API. There are also some rules to create REST API. I will post another article for the Rules but this is the core concept and methods of RESTful API.

Conclusion:

For now, Developers have used RESTful APIs to add functionality to their websites and apps. Today, the RESTful APIs are known as the “backbone of the Internet.”

Sources:

https://www.tutorialswebsite.com/

https://www.smashingmagazine.com/


Recommend

  • 48
    • www.ruanyifeng.com 6 years ago
    • Cache

    RESTful API 最佳实践

    RESTful 是目前最流行的 API 设计规范,用于 Web 数据接口的设计。 它的大原则容易把握,但是细节不容易做对。本文总结 RESTful 的设计细节,介绍如何设计出易于理解和使用的 API。

  • 36
    • www.ibm.com 6 years ago
    • Cache

    Restful API 监控实践

    概述 随着 docker 等技术的兴起,“微服务”的概念也越来越受青睐,日益增多的 web service 逐渐统一于 RESTful 架构风格,使得增量开发的代价越来越小。对于众多同时运行在 RESTful 架构下的服务而言,各种状态的管理及监控成为...

  • 36
    • insights.thoughtworks.cn 6 years ago
    • Cache

    细说API – 重新认识RESTful

    如果你是一个客户端、前端开发者,你可能会在某个时间吐槽过后端工程师的API设计,原因可能是文档不完善、返回数据丢字段、错误码不清晰等。如果你是一个后端API开发者,你一定在某些时候感到困惑,怎么让接口URL设计的合理,数据格式怎么...

  • 51
    • 微信 mp.weixin.qq.com 6 years ago
    • Cache

    细说API - 重新认识RESTful

  • 31
    • 掘金 juejin.im 5 years ago
    • Cache

    你真的了解restful api吗?

    前言 在以前,一个网站的完成总是“all in one”,页面,数据,渲染全部在服务端完成,这样做的最大的弊端是后期维护,扩展极其痛苦,开发人员必须同时具备前后端知识。于是慢慢的后来兴起了前后端分离的思想: 后端负责数据编造,而前端则负责数据渲染,前端静态页面...

  • 25
    • niyanchun.com 4 years ago
    • Cache

    如何设计RESTful API

    在如今的互联网时代,Web服务随处可见,REST这个词也经常出现。特别是现在微服务架构和前后端分离架构日益盛行,服务间越来越多的采用RESTful API通信,Java这门语言更是在Java SE 5中制定了JAX-RS(Jakarta/Java RESTful Web Services)规...

  • 8

    WebApi系列~基于RESTful标准的Web Api

  • 8

    Tutorial: Developing a RESTful API with Go and Gin This tutorial introduces the basics of writing a RESTful web service API with Go and the Gin Web Framework (Gin). You’ll get...

  • 5

    Understanding JavaScript Prototypes and Its MethodsOctober 17th 2022 new story4

  • 11

    Given the rapidly evolving realm of software development, creating a RESTful API is a crucial skill. But what exactly is a RESTful API, and why should you consider using Node.js and Express to create one?  Today, we’ll explore the fundament...

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK