Posts

Articles de blog liés à un utilisateur.

100 entrées initiales

Tester

Méthode
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
body string Obligatoire 5000 caractères au maximum

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, à combiner avec _start et _limit. Exemple : /api/posts?userId=1&_limit=5.

Routes imbriquées

  • GET /api/posts/{id}/comments : Commentaires du post

Exemples

Codes de retour : 200

JAVASCRIPT
fetch('https://www.api-placeholder.frederickagathe.fr/api/posts?_limit=10')
  .then((response) => response.json())
  .then((json) => console.log(json));

Codes de retour : 200, 404

JAVASCRIPT
fetch('https://www.api-placeholder.frederickagathe.fr/api/posts/1')
  .then((response) => response.json())
  .then((json) => console.log(json));

Codes de retour : 201, 400, 422

JAVASCRIPT
fetch('https://www.api-placeholder.frederickagathe.fr/api/posts', {
  method: 'POST',
  headers: { 'Content-type': 'application/json; charset=UTF-8' },
  body: JSON.stringify({
    "title": "Mon nouveau post",
    "body": "Contenu enregistré en base de données",
    "userId": 1
}),
})
  .then((response) => response.json())
  .then((json) => console.log(json));

Codes de retour : 200, 400, 404, 422

JAVASCRIPT
fetch('https://www.api-placeholder.frederickagathe.fr/api/posts/1', {
  method: 'PUT',
  headers: { 'Content-type': 'application/json; charset=UTF-8' },
  body: JSON.stringify({
    "title": "Mon nouveau post",
    "body": "Contenu enregistré en base de données",
    "userId": 1
}),
})
  .then((response) => response.json())
  .then((json) => console.log(json));

Codes de retour : 200, 400, 404, 422

JAVASCRIPT
fetch('https://www.api-placeholder.frederickagathe.fr/api/posts/1', {
  method: 'PATCH',
  headers: { 'Content-type': 'application/json; charset=UTF-8' },
  body: JSON.stringify({
    "title": "Titre modifié"
}),
})
  .then((response) => response.json())
  .then((json) => console.log(json));

Codes de retour : 204

JAVASCRIPT
fetch('https://www.api-placeholder.frederickagathe.fr/api/posts/1', { method: 'DELETE' })
  .then((response) => console.log(response.status)); // 204, sans contenu