MENU

# Introdução

Base URL: `https://api.sunstone.com.br/`

Esta documentação tem como objetivo fornecer todas as informações que você precisa para trabalhar com nossa API.

Ao rolar, você verá exemplos de código para trabalhar com a API em diferentes linguagens de programação na área escura à direita (ou como parte do conteúdo em dispositivos móveis). Você pode alterar o idioma usado nas guias no canto superior direito (ou no menu de navegação no canto superior esquerdo no celular).

# Autenticando solicitações

Esta API não está autenticada.

# Posts

## Listar todos os posts Este endpoint retorna uma lista de todos os posts não deletados.

requires authentication

> Example request:

    curl --request GET \
        --get "https://api.sunstone.com.br/api/v1/posts" \
        --header "Authorization: Bearer 1|LinnYgzxQm7zEQjdKg84GClWcTHfSrd0pGN9LLdWac9515e5" \
        --header "Content-Type: application/json" \
        --header "Accept: application/json"

    const url = new URL(
        "https://api.sunstone.com.br/api/v1/posts"
    );

    const headers = {
        "Authorization": "Bearer 1|LinnYgzxQm7zEQjdKg84GClWcTHfSrd0pGN9LLdWac9515e5",
        "Content-Type": "application/json",
        "Accept": "application/json",
    };

    fetch(url, {
        method: "GET",
        headers,
    }).then(response => response.json());

> Example response (200):

    {
        "id": 1,
        "title": "Meu primeiro post",
        "content": "Este é o conteúdo do post.",
        "author_id": 1,
        "created_at": "2023-08-30T19:20:02.000000Z",
        "updated_at": "2023-08-30T19:20:02.000000Z"
    }

> Example response (404):

    {
        "error": "Nenhuma post foi encontrada."
    }

> Received response:

> Request failed with error:

    Tip: Check that you're properly connected to the network.
    If you're a maintainer of ths API, verify that your API is running and you've enabled CORS.
    You can check the Dev Tools console for debugging information.

### Request

GET `api/v1/posts`

#### Headers

`Authorization`

Example: `Bearer 1|LinnYgzxQm7zEQjdKg84GClWcTHfSrd0pGN9LLdWac9515e5`

`Content-Type`

Example: `application/json`

`Accept`

Example: `application/json`

## Criar um novo post Este endpoint permite criar um novo post.

requires authentication

> Example request:

    curl --request GET \
        --get "https://api.sunstone.com.br/api/v1/posts/create" \
        --header "Authorization: Bearer 1|LinnYgzxQm7zEQjdKg84GClWcTHfSrd0pGN9LLdWac9515e5" \
        --header "Content-Type: application/json" \
        --header "Accept: application/json" \
        --data "{
        \"title\": \"praesentium\",
        \"content\": \"sint\",
        \"author_id\": 17,
        \"image\": \"fugit\"
    }"

    const url = new URL(
        "https://api.sunstone.com.br/api/v1/posts/create"
    );

    const headers = {
        "Authorization": "Bearer 1|LinnYgzxQm7zEQjdKg84GClWcTHfSrd0pGN9LLdWac9515e5",
        "Content-Type": "application/json",
        "Accept": "application/json",
    };

    let body = {
        "title": "praesentium",
        "content": "sint",
        "author_id": 17,
        "image": "fugit"
    };

    fetch(url, {
        method: "GET",
        headers,
        body: JSON.stringify(body),
    }).then(response => response.json());

> Example response (201):

    {
        "message": "Post criado com sucesso.",
        "data": {
            "id": 1,
            "title": "Meu novo post",
            "content": "Este é o conteúdo do post.",
            "author_id": 1,
            "created_at": "2023-08-30T19:20:02.000000Z",
            "updated_at": "2023-08-30T19:20:02.000000Z"
        }
    }

> Example response (422):

    {
        "error": "Erro de validação",
        "messages": {
            "title": [
                "O campo título é obrigatório."
            ],
            "content": [
                "O campo conteúdo é obrigatório."
            ]
        }
    }

> Example response (500):

    {
        "error": "Erro no banco de dados."
    }

> Received response:

> Request failed with error:

    Tip: Check that you're properly connected to the network.
    If you're a maintainer of ths API, verify that your API is running and you've enabled CORS.
    You can check the Dev Tools console for debugging information.

### Request

GET `api/v1/posts/create`

#### Headers

`Authorization`

Example: `Bearer 1|LinnYgzxQm7zEQjdKg84GClWcTHfSrd0pGN9LLdWac9515e5`

`Content-Type`

Example: `application/json`

`Accept`

Example: `application/json`

#### Body Parameters

`title` string

O título do post. Exemplo: Meu novo post Example: `praesentium`

`content` string

O conteúdo do post. Example: `sint`

`author_id` integer

O ID do autor. Exemplo: 1 Example: `17`

`image` string optional

O link da imagem. Exemplo: http://exemplo.com/imagem.png Example: `fugit`

## Exibir um post Este endpoint retorna os detalhes de um post específico.

requires authentication

> Example request:

    curl --request GET \
        --get "https://api.sunstone.com.br/api/v1/posts/11" \
        --header "Authorization: Bearer 1|LinnYgzxQm7zEQjdKg84GClWcTHfSrd0pGN9LLdWac9515e5" \
        --header "Content-Type: application/json" \
        --header "Accept: application/json"

    const url = new URL(
        "https://api.sunstone.com.br/api/v1/posts/11"
    );

    const headers = {
        "Authorization": "Bearer 1|LinnYgzxQm7zEQjdKg84GClWcTHfSrd0pGN9LLdWac9515e5",
        "Content-Type": "application/json",
        "Accept": "application/json",
    };

    fetch(url, {
        method: "GET",
        headers,
    }).then(response => response.json());

> Example response (200):

    {
        "id": 1,
        "title": "Meu primeiro post",
        "content": "Este é o conteúdo do post.",
        "author_id": 1,
        "created_at": "2023-08-30T19:20:02.000000Z",
        "updated_at": "2023-08-30T19:20:02.000000Z"
    }

> Example response (404):

    {
        "error": "Post não encontrado."
    }

> Example response (500):

    {
        "error": "Erro no banco de dados."
    }

> Received response:

> Request failed with error:

    Tip: Check that you're properly connected to the network.
    If you're a maintainer of ths API, verify that your API is running and you've enabled CORS.
    You can check the Dev Tools console for debugging information.

### Request

GET `api/v1/posts/{id}`

#### Headers

`Authorization`

Example: `Bearer 1|LinnYgzxQm7zEQjdKg84GClWcTHfSrd0pGN9LLdWac9515e5`

`Content-Type`

Example: `application/json`

`Accept`

Example: `application/json`

#### URL Parameters

`id` integer

O ID do post. Exemplo: 1 Example: `11`

## Atualizar um post Este endpoint permite atualizar um post existente.

requires authentication

> Example request:

    curl --request PUT \
        "https://api.sunstone.com.br/api/v1/posts/14" \
        --header "Authorization: Bearer 1|LinnYgzxQm7zEQjdKg84GClWcTHfSrd0pGN9LLdWac9515e5" \
        --header "Content-Type: application/json" \
        --header "Accept: application/json" \
        --data "{
        \"title\": \"debitis\",
        \"content\": \"molestias\",
        \"author_id\": 17,
        \"image\": \"sit\"
    }"

    const url = new URL(
        "https://api.sunstone.com.br/api/v1/posts/14"
    );

    const headers = {
        "Authorization": "Bearer 1|LinnYgzxQm7zEQjdKg84GClWcTHfSrd0pGN9LLdWac9515e5",
        "Content-Type": "application/json",
        "Accept": "application/json",
    };

    let body = {
        "title": "debitis",
        "content": "molestias",
        "author_id": 17,
        "image": "sit"
    };

    fetch(url, {
        method: "PUT",
        headers,
        body: JSON.stringify(body),
    }).then(response => response.json());

> Example response (200):

    {
        "message": "Post atualizado com sucesso.",
        "data": {
            "id": 1,
            "title": "Título atualizado",
            "content": "Conteúdo atualizado",
            "author_id": 1,
            "created_at": "2023-08-30T19:20:02.000000Z",
            "updated_at": "2023-08-30T19:40:02.000000Z"
        }
    }

> Example response (404):

    {
        "error": "Post não encontrado."
    }

> Example response (422):

    {
        "error": "Erro de validação",
        "messages": {
            "title": [
                "O campo título é obrigatório."
            ],
            "content": [
                "O campo conteúdo é obrigatório."
            ]
        }
    }

> Example response (500):

    {
        "error": "Erro no banco de dados."
    }

> Received response:

> Request failed with error:

    Tip: Check that you're properly connected to the network.
    If you're a maintainer of ths API, verify that your API is running and you've enabled CORS.
    You can check the Dev Tools console for debugging information.

### Request

PUT `api/v1/posts/{id}`

PATCH `api/v1/posts/{id}`

#### Headers

`Authorization`

Example: `Bearer 1|LinnYgzxQm7zEQjdKg84GClWcTHfSrd0pGN9LLdWac9515e5`

`Content-Type`

Example: `application/json`

`Accept`

Example: `application/json`

#### URL Parameters

`id` integer

O ID do post. Exemplo: 1 Example: `14`

#### Body Parameters

`title` string optional

O novo título do post. Exemplo: Título atualizado Example: `debitis`

`content` string optional

O novo conteúdo do post. Example: `molestias`

`author_id` integer optional

O ID atualizado do autor. Example: `17`

`image` string optional

O novo link da imagem. Example: `sit`

## Excluir um post Este endpoint marca um post como excluído.

requires authentication

> Example request:

    curl --request DELETE \
        "https://api.sunstone.com.br/api/v1/posts/9" \
        --header "Authorization: Bearer 1|LinnYgzxQm7zEQjdKg84GClWcTHfSrd0pGN9LLdWac9515e5" \
        --header "Content-Type: application/json" \
        --header "Accept: application/json"

    const url = new URL(
        "https://api.sunstone.com.br/api/v1/posts/9"
    );

    const headers = {
        "Authorization": "Bearer 1|LinnYgzxQm7zEQjdKg84GClWcTHfSrd0pGN9LLdWac9515e5",
        "Content-Type": "application/json",
        "Accept": "application/json",
    };

    fetch(url, {
        method: "DELETE",
        headers,
    }).then(response => response.json());

> Example response (200):

    {
        "message": "Post excluído com sucesso."
    }

> Example response (404):

    {
        "error": "Post não encontrado."
    }

> Example response (500):

    {
        "error": "Erro no banco de dados."
    }

> Received response:

> Request failed with error:

    Tip: Check that you're properly connected to the network.
    If you're a maintainer of ths API, verify that your API is running and you've enabled CORS.
    You can check the Dev Tools console for debugging information.

### Request

DELETE `api/v1/posts/{id}`

#### Headers

`Authorization`

Example: `Bearer 1|LinnYgzxQm7zEQjdKg84GClWcTHfSrd0pGN9LLdWac9515e5`

`Content-Type`

Example: `application/json`

`Accept`

Example: `application/json`

#### URL Parameters

`id` integer

O ID do post. Exemplo: 1 Example: `9`

## Criar um novo post Este endpoint permite criar um novo post.

requires authentication

> Example request:

    curl --request POST \
        "https://api.sunstone.com.br/api/v1/post/create" \
        --header "Authorization: Bearer 1|LinnYgzxQm7zEQjdKg84GClWcTHfSrd0pGN9LLdWac9515e5" \
        --header "Content-Type: application/json" \
        --header "Accept: application/json" \
        --data "{
        \"title\": \"non\",
        \"content\": \"et\",
        \"author_id\": 7,
        \"image\": \"odio\"
    }"

    const url = new URL(
        "https://api.sunstone.com.br/api/v1/post/create"
    );

    const headers = {
        "Authorization": "Bearer 1|LinnYgzxQm7zEQjdKg84GClWcTHfSrd0pGN9LLdWac9515e5",
        "Content-Type": "application/json",
        "Accept": "application/json",
    };

    let body = {
        "title": "non",
        "content": "et",
        "author_id": 7,
        "image": "odio"
    };

    fetch(url, {
        method: "POST",
        headers,
        body: JSON.stringify(body),
    }).then(response => response.json());

> Example response (201):

    {
        "message": "Post criado com sucesso.",
        "data": {
            "id": 1,
            "title": "Meu novo post",
            "content": "Este é o conteúdo do post.",
            "author_id": 1,
            "created_at": "2023-08-30T19:20:02.000000Z",
            "updated_at": "2023-08-30T19:20:02.000000Z"
        }
    }

> Example response (422):

    {
        "error": "Erro de validação",
        "messages": {
            "title": [
                "O campo título é obrigatório."
            ],
            "content": [
                "O campo conteúdo é obrigatório."
            ]
        }
    }

> Example response (500):

    {
        "error": "Erro no banco de dados."
    }

> Received response:

> Request failed with error:

    Tip: Check that you're properly connected to the network.
    If you're a maintainer of ths API, verify that your API is running and you've enabled CORS.
    You can check the Dev Tools console for debugging information.

### Request

POST `api/v1/post/create`

#### Headers

`Authorization`

Example: `Bearer 1|LinnYgzxQm7zEQjdKg84GClWcTHfSrd0pGN9LLdWac9515e5`

`Content-Type`

Example: `application/json`

`Accept`

Example: `application/json`

#### Body Parameters

`title` string

O título do post. Exemplo: Meu novo post Example: `non`

`content` string

O conteúdo do post. Example: `et`

`author_id` integer

O ID do autor. Exemplo: 1 Example: `7`

`image` string optional

O link da imagem. Exemplo: http://exemplo.com/imagem.png Example: `odio`

## Exibir um post Este endpoint retorna os detalhes de um post específico.

requires authentication

> Example request:

    curl --request POST \
        "https://api.sunstone.com.br/api/v1/post/1" \
        --header "Authorization: Bearer 1|LinnYgzxQm7zEQjdKg84GClWcTHfSrd0pGN9LLdWac9515e5" \
        --header "Content-Type: application/json" \
        --header "Accept: application/json"

    const url = new URL(
        "https://api.sunstone.com.br/api/v1/post/1"
    );

    const headers = {
        "Authorization": "Bearer 1|LinnYgzxQm7zEQjdKg84GClWcTHfSrd0pGN9LLdWac9515e5",
        "Content-Type": "application/json",
        "Accept": "application/json",
    };

    fetch(url, {
        method: "POST",
        headers,
    }).then(response => response.json());

> Example response (200):

    {
        "id": 1,
        "title": "Meu primeiro post",
        "content": "Este é o conteúdo do post.",
        "author_id": 1,
        "created_at": "2023-08-30T19:20:02.000000Z",
        "updated_at": "2023-08-30T19:20:02.000000Z"
    }

> Example response (404):

    {
        "error": "Post não encontrado."
    }

> Example response (500):

    {
        "error": "Erro no banco de dados."
    }

> Received response:

> Request failed with error:

    Tip: Check that you're properly connected to the network.
    If you're a maintainer of ths API, verify that your API is running and you've enabled CORS.
    You can check the Dev Tools console for debugging information.

### Request

POST `api/v1/post/{$id}`

#### Headers

`Authorization`

Example: `Bearer 1|LinnYgzxQm7zEQjdKg84GClWcTHfSrd0pGN9LLdWac9515e5`

`Content-Type`

Example: `application/json`

`Accept`

Example: `application/json`

#### URL Parameters

`$id` string

Example: `magni`

`id` integer

O ID do post. Exemplo: 1 Example: `19`