strapi/docs/3.0.0-beta.x/guides/api-endpoints.md
2019-08-26 15:20:49 +02:00

2.8 KiB

API Endpoints

When you create a ContentType you will have a certain number of API endpoints available to interact with it.

As an example let's consider the Post ContentType for the next steps.

Post ContentType

Fields Type Description
title string Post's title
cover media Post's cover image
seo group Post's seo group

Seo Group

Fields Type Description
name string Meta's name
content text Meta's content

Endpoints

Method Path Description
GET /posts Get a list of posts
GET /posts/count Count posts
POST /posts Create a post
GET /posts/:id Get a specific post
PUT /posts/:id Update a post
DELETE /posts/:id Delete a post

GET /posts

This endpoint returns the list of posts matching your filters. Youc an read more about filtering here.

Example request

GET http://localhost:1337/posts

Example response

[
  {
    "id": "1",
    "title": "Post 1",
    "cover": {
      "id": "1",
      "url": "/uploads/3d89ba92f762433bbb75bbbfd9c13974.png"
      //...
    }
    // This is a group
    "seo": [
      {
        "id": "1",
        "name": "description",
        "content": "This is a press post about Strapi"
      },
      {
        "id": "2",
        "name": "keywords",
        "content": "post, article, news, press"
      }
    ]
  }
]

GET /posts/count

Example response

1

POST /posts

Example request

POST http://localhost:1337/posts
{
  "title": "Post 2",
  "cover": 1,
  "seo": [
    {
      "name": "title",
      "content": "Post 2"
    }
  ]
}

Example response

  {
    "id": "1",
    "title": "Post 1",
    "cover": {
      "id": "1",
      "url": "/uploads/3d89ba92f762433bbb75bbbfd9c13974.png"
      //...
    }
    // This is a group
    "seo": [
      {
        "id": 3,
        "name": "title",
        "content": "Post 2"
      }
    ]
  }

GET /posts/:id

PUT /posts/:id

DELETE /posts/:id