Comments

Commentaires liés à un post.

500 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
postId integer Obligatoire Post existant, sinon 400
name string Obligatoire 255 caractères au maximum
email string Facultatif Format email valide
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

postId, name, email, à combiner avec _start et _limit. Exemple : /api/comments?postId=1&_limit=5.

Exemples

Codes de retour : 200

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

Codes de retour : 200, 404

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

Codes de retour : 201, 400, 422

JAVASCRIPT
fetch('https://api-placeholder.frederickagathe.fr/api/comments', {
  method: 'POST',
  headers: { 'Content-type': 'application/json; charset=UTF-8' },
  body: JSON.stringify({
    "postId": 1,
    "name": "Mon commentaire",
    "email": "jane@exemple.com",
    "body": "Merci pour cet article"
}),
})
  .then((response) => response.json())
  .then((json) => console.log(json));

Codes de retour : 200, 400, 404, 422

JAVASCRIPT
fetch('https://api-placeholder.frederickagathe.fr/api/comments/1', {
  method: 'PUT',
  headers: { 'Content-type': 'application/json; charset=UTF-8' },
  body: JSON.stringify({
    "postId": 1,
    "name": "Mon commentaire",
    "email": "jane@exemple.com",
    "body": "Merci pour cet article"
}),
})
  .then((response) => response.json())
  .then((json) => console.log(json));

Codes de retour : 200, 400, 404, 422

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

Codes de retour : 204

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