Skip to content

Commit

Permalink
localStorage, fetch, axios, supabase
Browse files Browse the repository at this point in the history
  • Loading branch information
luizchaves committed Sep 8, 2023
1 parent 9020f9c commit 4aeb97a
Show file tree
Hide file tree
Showing 20 changed files with 791 additions and 41 deletions.
11 changes: 6 additions & 5 deletions public/codes/api/rest/github-api.http
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
@host=https://api.github.com
@token={{$dotenv GITHUB_TOKEN}}
@username=lucachaves
@repo=github-repo-api


### Create a repository
POST https://api.github.com/user/repos
POST {{host}}/user/repos
Accept: application/vnd.github+json
Authorization: Bearer {{token}}
X-GitHub-Api-Version: 2022-11-28
Expand All @@ -19,19 +20,19 @@ Content-Type: application/json
}

### Read repositories
GET https://api.github.com/users/{{username}}/repos
GET {{host}}/users/{{username}}/repos
Accept: application/vnd.github+json
Authorization: Bearer {{token}}
X-GitHub-Api-Version: 2022-11-28

### Read a repository
GET https://api.github.com/repos/{{username}}/{{repo}}
GET {{host}}/repos/{{username}}/{{repo}}
Accept: application/vnd.github+json
Authorization: Bearer {{token}}
X-GitHub-Api-Version: 2022-11-28

### Update a repository
PATCH https://api.github.com/repos/{{username}}/{{repo}}
PATCH {{host}}/repos/{{username}}/{{repo}}
Accept: application/vnd.github+json
Authorization: Bearer {{token}}
X-GitHub-Api-Version: 2022-11-28
Expand All @@ -46,7 +47,7 @@ Content-Type: application/json
}

### Delete a repository
DELETE https://api.github.com/repos/{{username}}/{{repo}}
DELETE {{host}}/repos/{{username}}/{{repo}}
Accept: application/vnd.github+json
Authorization: Bearer {{token}}
X-GitHub-Api-Version: 2022-11-28
1 change: 1 addition & 0 deletions public/codes/package/supabase-api/.env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
SUPABASE_KEY=
43 changes: 43 additions & 0 deletions public/codes/package/supabase-api/invest-api.http
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
@host = https://qxxivxowaxwsgeruydka.supabase.co
@token = {{$dotenv SUPABASE_KEY}}
@createdInvestmentId = {{createInvestment.response.body.$[0].id}}

### Create a investment
# @name createInvestment
POST {{host}}/rest/v1/investments
apikey: {{token}}
Authorization: Bearer {{token}}
Content-Type: application/json
Prefer: return=representation

{
"name": "Tesouro Selic 2029",
"value": 10000
}

### Read investments
GET {{host}}/rest/v1/investments?select=*
apikey: {{token}}
Authorization: Bearer {{token}}

### Read a investment
GET {{host}}/rest/v1/investments?id=eq.{{createdInvestmentId}}
apikey: {{token}}
Authorization: Bearer {{token}}


### Update a investment
PATCH {{host}}/rest/v1/investments?id=eq.{{createdInvestmentId}}
apikey: {{token}}
Authorization: Bearer {{token}}
Content-Type: application/json
Prefer: return=representation

{
"value": 15000
}

### Delete a investment
DELETE {{host}}/rest/v1/investments?id=eq.{{createdInvestmentId}}
apikey: {{token}}
Authorization: Bearer {{token}}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
10 changes: 10 additions & 0 deletions public/imgs/package/supabase-api/delete-investment.pu
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
@startuml
title DELETE
hide footbox
skinparam monochrome true

Client -> Server: DELETE /rest/v1/investments?id=eq.1
note right: DELETE /rest/v1/investments?id=eq.1 HTTP/1.1\nHost: https://xyz.supabase.co\napikey: TOKEN\nAuthorization: Bearer TOKEN
Server -> Client: HTTP/1.1 204 No Content
note left: HTTP/1.1 204 No Content
@enduml
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
10 changes: 10 additions & 0 deletions public/imgs/package/supabase-api/get-investment.pu
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
@startuml
title GET
hide footbox
skinparam monochrome true

Client -> Server: GET /rest/v1/investments?id=eq.1
note right: GET /rest/v1/investments?id=eq.1 HTTP/1.1\nHost: https://xyz.supabase.co\napikey: TOKEN\nAuthorization: Bearer TOKEN
Server -> Client: HTTP/1.1 200 OK
note left: HTTP/1.1 200 OK\n\n[\n {\n "id": 1,\n "name": "Tesouro Selic 2029",\n "name": "algorithms",\n "value": 10000,\n "created_at": "2023-09-08T01:58:13.676422+00:00"\n }\n]
@enduml
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
10 changes: 10 additions & 0 deletions public/imgs/package/supabase-api/get-investments.pu
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
@startuml
title GET
hide footbox
skinparam monochrome true

Client -> Server: GET /rest/v1/investments?select=*
note right: GET /rest/v1/investments?select=* HTTP/1.1\nHost: https://xyz.supabase.co\napikey: TOKEN\nAuthorization: Bearer TOKEN
Server -> Client: HTTP/1.1 200 OK
note left: HTTP/1.1 200 OK\n\n[\n {\n "id": 1,\n "name": "Tesouro Selic 2029",\n "name": "algorithms",\n "value": 10000,\n "created_at": "2023-09-08T01:58:13.676422+00:00"\n },\n ...\n]
@enduml
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
10 changes: 10 additions & 0 deletions public/imgs/package/supabase-api/patch-investment.pu
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
@startuml
title PATCH
hide footbox
skinparam monochrome true

Client -> Server: PATCH /rest/v1/investments?id=eq.1
note right: PATCH /rest/v1/investments?id=eq.1 HTTP/1.1\nHost: https://xyz.supabase.co\napikey: TOKEN\nAuthorization: Bearer TOKEN\nPrefer: return=representation\nContent-Type: application/json\n\n{\n "value": 15000\n}
Server -> Client: HTTP/1.1 200 OK
note left: HTTP/1.1 200 OK\n\n[\n {\n "id": 1,\n "name": "Tesouro Selic 2029",\n "name": "algorithms",\n "value": 15000,\n "created_at": "2023-09-08T01:58:13.676422+00:00"\n }\n]
@enduml
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
10 changes: 10 additions & 0 deletions public/imgs/package/supabase-api/post-investment.pu
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
@startuml
title POST
hide footbox
skinparam monochrome true

Client -> Server: POST /rest/v1/investments
note right: POST /rest/v1/investments HTTP/1.1\nHost: https://xyz.supabase.co\napikey: TOKEN\nAuthorization: Bearer TOKEN\nPrefer: return=representation\nContent-Type: application/json\n\n{\n "name": "Tesouro Selic 2029",\n "value": 10000\n}
Server -> Client: HTTP/1.1 201 Created
note left: HTTP/1.1 201 Created\n\n[\n {\n "id": 1,\n "name": "Tesouro Selic 2029",\n "name": "algorithms",\n "value": 10000,\n "created_at": "2023-09-08T01:58:13.676422+00:00"\n }\n]
@enduml
10 changes: 5 additions & 5 deletions src/consts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@ export const CLASSNOTE_SLUGS = [
'package/vite',
'w3c/event-handling',
'w3c/dom-api',
'w3c/local-storage',
'api/rest',
// 'package/supabase-api',
// 'w3c/fetch-api',
// 'package/axios',
// 'package/supabase-client',
// 'w3c/crud-elements',
'package/supabase-api',
'w3c/fetch-api',
'package/axios',
'package/supabase-client',
// 'react/introduction-react',
];

Expand Down
46 changes: 25 additions & 21 deletions src/content/classnotes/api/rest/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -43,16 +43,13 @@ Exemplos:
- [{'https://api.github.com/repos/ifpb/ls'}](https://api.github.com/repos/ifpb/ls)
{/* - [Exemplo](https://ifpb.github.io/challenges/web/front-end/js/github-profile-comparator/) */}

### Rotas
### Token

| Método | Caminho | Status | Resposta |
| ------ | -------------------------------------- | ------ | --------------------------------------------- |
| POST | `/user/repos` | `201` | Cria um novo repositório |
| GET | `/users/lucachaves/repos` | `200` | Retorna todos os repositórios |
| GET | `/users/lucachaves/repos?type=private` | `200` | Retorna todos os repositórios privados |
| GET | `/repos/lucachaves/ls` | `200` | Retorna o repositório com nome lucachaves/ls |
| PATCH | `/repos/lucachaves/ls` | `200` | Atualiza o repositório com nome lucachaves/ls |
| DELETE | `/repos/lucachaves/ls` | `204` | Exclui o repositório com nome lucachaves/ls |
- [Managing your personal access tokens](https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/managing-your-personal-access-tokens)
- [Authenticating to the REST API](https://docs.github.com/en/rest/overview/authenticating-to-the-rest-api?apiVersion=2022-11-28)
- [Authenticating with a personal access token](https://docs.github.com/en/rest/overview/authenticating-to-the-rest-api?apiVersion=2022-11-28#authenticating-with-a-personal-access-token)
- [Quickstart for GitHub REST API](https://docs.github.com/en/rest/quickstart?apiVersion=2022-11-28)
- [Getting started using curl](https://docs.github.com/en/rest/quickstart?apiVersion=2022-11-28#getting-started-using-curl)

### HTTP

Expand All @@ -75,27 +72,30 @@ Exemplos de Códigos
| `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. |

### Token

- [Managing your personal access tokens](https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/managing-your-personal-access-tokens)
- [Authenticating to the REST API](https://docs.github.com/en/rest/overview/authenticating-to-the-rest-api?apiVersion=2022-11-28)
- [Authenticating with a personal access token](https://docs.github.com/en/rest/overview/authenticating-to-the-rest-api?apiVersion=2022-11-28#authenticating-with-a-personal-access-token)
- [Quickstart for GitHub REST API](https://docs.github.com/en/rest/quickstart?apiVersion=2022-11-28)
- [Getting started using curl](https://docs.github.com/en/rest/quickstart?apiVersion=2022-11-28#getting-started-using-curl)

### Rotas

| Método | Caminho | Status | Resposta |
| ------ | -------------------------------------- | ------ | --------------------------------------------- |
| POST | `/user/repos` | `201` | Cria um novo repositório |
| GET | `/users/lucachaves/repos` | `200` | Retorna todos os repositórios |
| GET | `/users/lucachaves/repos?type=private` | `200` | Retorna todos os repositórios privados |
| GET | `/repos/lucachaves/ls` | `200` | Retorna o repositório com nome lucachaves/ls |
| PATCH | `/repos/lucachaves/ls` | `200` | Atualiza o repositório com nome lucachaves/ls |
| DELETE | `/repos/lucachaves/ls` | `204` | Exclui o repositório com nome lucachaves/ls |

### Create a repository

![](/ls/imgs/api/rest/github-post-repository.png)

```http
@host=https://api.github.com
@token={{$dotenv GITHUB_TOKEN}}
@username=lucachaves
@repo=github-repo-api
###
POST https://api.github.com/user/repos
POST {{host}}/user/repos
Accept: application/vnd.github+json
Authorization: Bearer {{token}}
X-GitHub-Api-Version: 2022-11-28
Expand Down Expand Up @@ -128,11 +128,12 @@ $ curl -L \
![](/ls/imgs/api/rest/github-get-repositories.png)

```http
@host=https://api.github.com
@token={{$dotenv GITHUB_TOKEN}}
@username=lucachaves
###
GET https://api.github.com/users/{{username}}/repos
GET {{host}}/users/{{username}}/repos
Accept: application/vnd.github+json
Authorization: Bearer {{token}}
X-GitHub-Api-Version: 2022-11-28
Expand All @@ -153,13 +154,14 @@ $ curl -L \
![](/ls/imgs/api/rest/github-get-repository.png)

```http
@host=https://api.github.com
@token={{$dotenv GITHUB_TOKEN}}
@username=lucachaves
@repo=github-repo-api
###
GET https://api.github.com/repos/{{username}}/{{repo}}
GET {{host}}/repos/{{username}}/{{repo}}
Accept: application/vnd.github+json
Authorization: Bearer {{token}}
X-GitHub-Api-Version: 2022-11-28
Expand All @@ -181,12 +183,13 @@ $ curl -L \
![](/ls/imgs/api/rest/github-patch-repository.png)

```http
@host=https://api.github.com
@token={{$dotenv GITHUB_TOKEN}}
@username=lucachaves
@repo=github-repo-api
###
PATCH https://api.github.com/repos/{{username}}/{{repo}}
PATCH {{host}}/repos/{{username}}/{{repo}}
Accept: application/vnd.github+json
Authorization: Bearer {{token}}
X-GitHub-Api-Version: 2022-11-28
Expand Down Expand Up @@ -219,12 +222,13 @@ $ curl -L \
![](/ls/imgs/api/rest/github-delete-repository.png)

```http
@host=https://api.github.com
@token={{$dotenv GITHUB_TOKEN}}
@username=lucachaves
@repo=github-repo-api
###
DELETE https://api.github.com/repos/{{username}}/{{repo}}
DELETE {{host}}/repos/{{username}}/{{repo}}
Accept: application/vnd.github+json
Authorization: Bearer {{token}}
X-GitHub-Api-Version: 2022-11-28
Expand Down
Loading

0 comments on commit 4aeb97a

Please sign in to comment.