iT邦幫忙

第 12 屆 iThome 鐵人賽

DAY 8
0
Modern Web

用30days 了解web系列 第 8

(Day 08) what is RESTful API

  • 分享至 

  • xImage
  •  

for those out there maybe you've heard about API before, but many of us still don't really know what is API or RESTful API. Today's article will cover-up some API topics.
https://ithelp.ithome.com.tw/upload/images/20200921/20129609H5p63UD5o1.jpg

What is API?
API stands for Application Programming Interface. it is a set of rules that allows programs to talk to each other. The developer creates the API on the server and allows the clients to talk to it.
let's say you're trying to find Superman on Google. So you open up Google and type "Superman" than hit enter and you see a list of information about Superman. An API works in similar ways. You're searching for something and you sending a request to the server and the server sending you back a list of results back.

REST
REST stands for "Representational State Transfer". REST determines how to API looks like. it is a set of rules that developers follow when they create their API/.
for each URL is called a request while the data sent back to you is called a response.

The Anatomy of A Request
the request is made up of four things:

  1. the endpoint
  2. the method
  3. the headers
  4. the data or body

EndPoint
the endpoint we talking about here is the URL that we going to make the request. example when you go to https://api.twitter.com the endpoint is this case is twitter.

Method
GET
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.

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

PUT and PATCH
These two requests are used to update a resource on a server. If you perform a PUT or PATCH request, the server updates an entry in the database and tells you whether the update is successful. In other words, a PUT or PATCH request performs an UPDATE operation.

DELETE
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.

The Headers
the header is divided into 2 parts. there are Request and Response Headers. please check this link for a better understanding of API Headers.

The Data or Body
the data contains information you want to send to the server. when you go to Google and search "superman" you probably will go through:
google.com/?q=superman this 'q' means the query or the value that you wanted to search on Google. this data is only used for POST, PUT, PATCH, or DELETE request. on the body part, the data type could be variative, possibly the data could be written in JSON, XML, etc.

that's all for today, tomorrow we will do the code practices about API using Laravel.


上一篇
(Day 07) Creating CRUD with Laravel, Mysql, Bootstrap part III
下一篇
(Day 09) retrieving database data using API method
系列文
用30days 了解web30
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言