ქვემოთ მოყვანილია API-ის სხვადასხვა endpoint-ების აღწერა:
Endpoint: GET /api/posts
აღწერა: აბრუნებს ყველა პოსტს.
მოთხოვნის მაგალითი:
fetch('https://warrior.ge/api/posts')
.then(response => response.json())
.then(data => console.log(data));
Endpoint: GET /api/posts/{id}
აღწერა: აბრუნებს კონკრეტულ პოსტს ID-ის მიხედვით.
მოთხოვნის მაგალითი:
fetch('https://warrior.ge/api/posts/1')
.then(response => response.json())
.then(data => console.log(data));
Endpoint: POST /api/posts/{id}
აღწერა: ახორციელებს პოსტის განახლებას.
მოთხოვნის მაგალითი:
fetch('https://warrior.ge/api/posts/1', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
title: 'ახალი სათაური',
body: 'განახლებული ტექსტი',
}),
})
.then(response => response.json())
.then(data => console.log(data));
Endpoint: POST /api/posts/{id}
აღწერა: შლის კონკრეტულ პოსტს ID-ის მიხედვით.
მოთხოვნის მაგალითი:
fetch('https://warrior.ge/api/posts/1', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
})
.then(response => response.json())
.then(data => console.log(data));