REST API
Web API
-
Exemplos de Web API
-
Web API Pública
ViaCEP API
https://viacep.com.br/ws/58015430/json/:
Código Fonte (Requisição | REST Client):
/codes/api/rest/viacep.http
@cep=58015430
GET https://viacep.com.br/ws/{{cep}}/json/
/codes/api/rest/viacep.http
@cep=58015430
GET https://viacep.com.br/ws/{{cep}}/json/
curl:
$ curl https://viacep.com.br/ws/58015430/json/
$ curl https://viacep.com.br/ws/58015430/json/
Github REST API
- Exemplos
- Token
- GitHub - REST API - Doc
Rotas
Código Fonte (Requisição | Rest Client)
Método | Caminho | Status | Resposta |
---|---|---|---|
POST | /user/repos | 201 | Cria um novo repositório |
GET | /users/luizchaves/repos | 200 | Retorna todos os repositórios |
GET | /users/luizchaves/repos?type=private | 200 | Retorna todos os repositórios privados |
GET | /repos/luizchaves/ls | 200 | Retorna o repositório com nome luizchaves/ls |
PATCH | /repos/luizchaves/ls | 200 | Atualiza o repositório com nome luizchaves/ls |
DELETE | /repos/luizchaves/ls | 204 | Exclui o repositório com nome luizchaves/ls |
- Respostas de informação (100-199)
- Respostas de sucesso (200-299)
- Redirecionamentos (300-399)
- Erros do cliente (400-499)
- Erros do servidor (500-599)
Exemplos de Códigos
Código | Nome | Significado |
---|---|---|
200 | Ok | Solicitação gerada com sucesso |
201 | Created | Solicitação gerada com sucesso e um novo recurso foi criado como resultado |
204 | No Content | Solicitação gerada com sucesso e não há conteúdo para ser enviado |
400 | Bad Request | Solicitação não compreendida por motivos de erro |
401 | Unauthorized | Solicitação foi bloqueada porque não possui credenciais de autenticação válidas |
404 | Not Found | O servidor não pode encontrar o recurso solicitado |
500 | Internal Server Error | O servidor encontrou uma situação com a qual não sabe lidar. |
Create a repository
GitHub - REST API - Create a repository for the authenticated user
/codes/api/rest/.env.example
GITHUB_TOKEN=
/codes/api/rest/.env.example
GITHUB_TOKEN=
@host=https://api.github.com
@token={{$dotenv GITHUB_TOKEN}}
@username=luizchaves
@repo=github-repo-api
###
POST {{host}}/user/repos
Accept: application/vnd.github+json
Authorization: Bearer {{token}}
X-GitHub-Api-Version: 2022-11-28
Content-Type: application/json
{
"name": "{{repo}}",
"description": "This is your first repo!",
"homepage": "https://github.com",
"private": false,
"is_template": true
}
@host=https://api.github.com
@token={{$dotenv GITHUB_TOKEN}}
@username=luizchaves
@repo=github-repo-api
###
POST {{host}}/user/repos
Accept: application/vnd.github+json
Authorization: Bearer {{token}}
X-GitHub-Api-Version: 2022-11-28
Content-Type: application/json
{
"name": "{{repo}}",
"description": "This is your first repo!",
"homepage": "https://github.com",
"private": false,
"is_template": true
}
$ TOKEN=abc
$ curl -L \
-X POST \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer ${TOKEN}" \
-H "X-GitHub-Api-Version: 2022-11-28" \
https://api.github.com/user/repos \
-d '{"name":"github-repo-api","description":"This is your first repo!","homepage":"https://github.com","private":false,"is_template":true}'
$ TOKEN=abc
$ curl -L \
-X POST \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer ${TOKEN}" \
-H "X-GitHub-Api-Version: 2022-11-28" \
https://api.github.com/user/repos \
-d '{"name":"github-repo-api","description":"This is your first repo!","homepage":"https://github.com","private":false,"is_template":true}'
Read repositories
GitHub - REST API - List repositories for a user
@host=https://api.github.com
@token={{$dotenv GITHUB_TOKEN}}
@username=luizchaves
###
GET {{host}}/users/{{username}}/repos
Accept: application/vnd.github+json
Authorization: Bearer {{token}}
X-GitHub-Api-Version: 2022-11-28
@host=https://api.github.com
@token={{$dotenv GITHUB_TOKEN}}
@username=luizchaves
###
GET {{host}}/users/{{username}}/repos
Accept: application/vnd.github+json
Authorization: Bearer {{token}}
X-GitHub-Api-Version: 2022-11-28
$ TOKEN=abc
$ curl -L \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer ${TOKEN}" \
-H "X-GitHub-Api-Version: 2022-11-28" \
https://api.github.com/users/luizchaves/repos
$ TOKEN=abc
$ curl -L \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer ${TOKEN}" \
-H "X-GitHub-Api-Version: 2022-11-28" \
https://api.github.com/users/luizchaves/repos
Read a repository (name)
GitHub - REST API - Get a repository
@host=https://api.github.com
@token={{$dotenv GITHUB_TOKEN}}
@username=luizchaves
@repo=github-repo-api
###
GET {{host}}/repos/{{username}}/{{repo}}
Accept: application/vnd.github+json
Authorization: Bearer {{token}}
X-GitHub-Api-Version: 2022-11-28
@host=https://api.github.com
@token={{$dotenv GITHUB_TOKEN}}
@username=luizchaves
@repo=github-repo-api
###
GET {{host}}/repos/{{username}}/{{repo}}
Accept: application/vnd.github+json
Authorization: Bearer {{token}}
X-GitHub-Api-Version: 2022-11-28
$ TOKEN=abc
$ curl -L \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer ${TOKEN}" \
-H "X-GitHub-Api-Version: 2022-11-28" \
https://api.github.com/repos/luizchaves/github-repo-api
$ TOKEN=abc
$ curl -L \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer ${TOKEN}" \
-H "X-GitHub-Api-Version: 2022-11-28" \
https://api.github.com/repos/luizchaves/github-repo-api
Update a repository
GitHub - REST API - Update a repository
@host=https://api.github.com
@token={{$dotenv GITHUB_TOKEN}}
@username=luizchaves
@repo=github-repo-api
###
PATCH {{host}}/repos/{{username}}/{{repo}}
Accept: application/vnd.github+json
Authorization: Bearer {{token}}
X-GitHub-Api-Version: 2022-11-28
Content-Type: application/json
{
"name": "{{repo}}",
"description": "This is your first repository",
"homepage": "https://github.com",
"private": false,
"is_template": false
}
@host=https://api.github.com
@token={{$dotenv GITHUB_TOKEN}}
@username=luizchaves
@repo=github-repo-api
###
PATCH {{host}}/repos/{{username}}/{{repo}}
Accept: application/vnd.github+json
Authorization: Bearer {{token}}
X-GitHub-Api-Version: 2022-11-28
Content-Type: application/json
{
"name": "{{repo}}",
"description": "This is your first repository",
"homepage": "https://github.com",
"private": false,
"is_template": false
}
$ TOKEN=abc
$ curl -L \
-X PATCH \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer ${TOKEN}" \
-H "X-GitHub-Api-Version: 2022-11-28" \
https://api.github.com/repos/luizchaves/github-repo-api \
-d '{"name":"github-repo-api","description":"This is your first repo!","homepage":"https://github.com","private":false,"is_template":false}'
$ TOKEN=abc
$ curl -L \
-X PATCH \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer ${TOKEN}" \
-H "X-GitHub-Api-Version: 2022-11-28" \
https://api.github.com/repos/luizchaves/github-repo-api \
-d '{"name":"github-repo-api","description":"This is your first repo!","homepage":"https://github.com","private":false,"is_template":false}'
Delete a repository
GitHub - REST API - Delete a repository
@host=https://api.github.com
@token={{$dotenv GITHUB_TOKEN}}
@username=luizchaves
@repo=github-repo-api
###
DELETE {{host}}/repos/{{username}}/{{repo}}
Accept: application/vnd.github+json
Authorization: Bearer {{token}}
X-GitHub-Api-Version: 2022-11-28
@host=https://api.github.com
@token={{$dotenv GITHUB_TOKEN}}
@username=luizchaves
@repo=github-repo-api
###
DELETE {{host}}/repos/{{username}}/{{repo}}
Accept: application/vnd.github+json
Authorization: Bearer {{token}}
X-GitHub-Api-Version: 2022-11-28
$ TOKEN=abc
$ curl -L \
-X DELETE \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer ${TOKEN}" \
-H "X-GitHub-Api-Version: 2022-11-28" \
https://api.github.com/repos/luizchaves/github-repo-api
$ TOKEN=abc
$ curl -L \
-X DELETE \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer ${TOKEN}" \
-H "X-GitHub-Api-Version: 2022-11-28" \
https://api.github.com/repos/luizchaves/github-repo-api