5

API?

REST API, API . API .

API Application Programming Interface. API .

, API, , . .

API. , , , . JSON XML.

, API, .

API , .


API

.

. , , , .

, , . , , .

- API, . API - . , , - , .


REST?

REST REpresentational State Transfer ( ). , , .

, , , , REST API.

API, REST RESTful.

HTTP. Create (), Read (), Update () and Delete () CRUD .

CRUD ?

, HTTP , , REST . REST , HTTP //, .


, REST API?

REST API

, REST API , HTTP . :

  • GET: get .
  • POST: post .
  • PATCH/PUT: patch .
  • DELETE: delete .

REST, CRUD . :

  • => POST
  • => GET
  • => PATCH/PUT
  • => DELETE

, , , GET / . URL.

, . , 200 - , 400 - .

JSONPlaceholder API, JavaScript:

fetch('https://jsonplaceholder.typicode.com/todos/1')
  .then(response => response.json())
  .then(json => console.log(json))

fetch API GET, . .

, - https://jsonplaceholder.typicode.com, - todo. JSON .

POST, POST, , .

, id todo, . :

fetch('https://jsonplaceholder.typicode.com/posts/3', {
  method: 'DELETE',
});	

, id . :

fetch('https://jsonplaceholder.typicode.com/posts/5', {
  method: 'PATCH',
  body: JSON.stringify({
    title: 'new todo',
  }),
  headers: {
    'Content-type': 'application/json; charset=UTF-8',
  },
})
  .then((response) => response.json())
  .then((json) => console.log(json));	

, REST .

API , . REST , , , .


50% Merion Academy