Todos
Tâches, à faire ou terminées, liées à un utilisateur.
200 entrées initialesTester
Réponse
…
Champs
| Champ | Type | POST et PUT | Règle |
|---|---|---|---|
id |
integer | Généré | Généré par l'API |
userId |
integer | Obligatoire | Utilisateur existant, sinon 400 |
title |
string | Obligatoire | 255 caractères au maximum |
completed |
boolean | Facultatif | false par défaut |
PATCH ne valide que les champs envoyés. Les données initiales ne sont jamais modifiées : la réponse montre seulement le résultat simulé. DELETE répond toujours 204 sans rien supprimer.
Filtres
userId, title, completed,
à combiner avec _start et _limit. Exemple :
/api/todos?userId=1&_limit=5.
Exemples
Codes de retour : 200
JAVASCRIPT
fetch('https://api-placeholder.frederickagathe.fr/api/todos?_limit=10')
.then((response) => response.json())
.then((json) => console.log(json));
Codes de retour : 200, 404
JAVASCRIPT
fetch('https://api-placeholder.frederickagathe.fr/api/todos/1')
.then((response) => response.json())
.then((json) => console.log(json));
Codes de retour : 201, 400, 422
JAVASCRIPT
fetch('https://api-placeholder.frederickagathe.fr/api/todos', {
method: 'POST',
headers: { 'Content-type': 'application/json; charset=UTF-8' },
body: JSON.stringify({
"userId": 1,
"title": "Ma tâche",
"completed": false
}),
})
.then((response) => response.json())
.then((json) => console.log(json));
Codes de retour : 200, 400, 404, 422
JAVASCRIPT
fetch('https://api-placeholder.frederickagathe.fr/api/todos/1', {
method: 'PUT',
headers: { 'Content-type': 'application/json; charset=UTF-8' },
body: JSON.stringify({
"userId": 1,
"title": "Ma tâche",
"completed": false
}),
})
.then((response) => response.json())
.then((json) => console.log(json));
Codes de retour : 200, 400, 404, 422
JAVASCRIPT
fetch('https://api-placeholder.frederickagathe.fr/api/todos/1', {
method: 'PATCH',
headers: { 'Content-type': 'application/json; charset=UTF-8' },
body: JSON.stringify({
"completed": true
}),
})
.then((response) => response.json())
.then((json) => console.log(json));
Codes de retour : 204
JAVASCRIPT
fetch('https://api-placeholder.frederickagathe.fr/api/todos/1', { method: 'DELETE' })
.then((response) => console.log(response.status)); // 204, sans contenu