https://github.com/ericneves/mybooksapi
š„ API RESTFul with PHP, Mysql, Routes, Authentication with Json Web Token, Validation and more...
https://github.com/ericneves/mybooksapi
api json-web-token jwt mysql php php-api sql
Last synced: 3 months ago
JSON representation
š„ API RESTFul with PHP, Mysql, Routes, Authentication with Json Web Token, Validation and more...
- Host: GitHub
- URL: https://github.com/ericneves/mybooksapi
- Owner: EricNeves
- License: mit
- Created: 2023-07-24T11:01:54.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2023-11-06T19:58:12.000Z (about 2 years ago)
- Last Synced: 2024-11-17T12:21:33.461Z (about 1 year ago)
- Topics: api, json-web-token, jwt, mysql, php, php-api, sql
- Language: PHP
- Homepage:
- Size: 684 KB
- Stars: 6
- Watchers: 1
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
- License: LICENSE
Awesome Lists containing this project
README
My Books API
API RESTFul desenvolvida com PHP, Mysql, autenticação por JWT, CRUD de dados, rotas e entre outros.
Data de criação: Jul 24, 2023
Features ā¢
How to User ?
How to Consume API ?


### Features
API desenvolvida com PHP, Mysql, Rotas, URL amigÔvel, autenticação por JWT, OOP e muito mais.
O projeto consiste da criação de usuÔrios, podendo cada usuÔrio, cadastrar, editar ou deletar seus livros.
* PHP
- JWT
- PDO (Mysql)
- OOP
- Routes
- SPL - Autoload
* MYSQL
- DDL
- DML
### How to use
Segue-se alguns passos para a execução da aplicação:
- Iniciar o servidor Apache e o Mysql.
- Configure o arquivo config.php com suas credenciais de banco de dados e edite o BASE_URL conforme a localização do projeto.
- Copie a pasta do projeto para dentro do servidor Apache.
- Ativar o ModRewrite: comando via terminal: ```a2enmod rewrite``` ou habilitar nas configuraƧƵes do Apache.
- Executar os comandos DDL e DML do arquivo database.sql, o arquivo se encontra na raiz do projeto.
### How to consume API
Nos exemplos de consumo da API, serĆ” utilizado a funcionalidade Fetch API do Javascript.
```js
/**
* @Route("/", methods: {"GET"})
*/
fetch('http://127.0.0.1/myBooksAPI/')
.then(res => res.json())
.then(console.log)
/* {
"message": "Hey There! š¦",
"guide": "https://github.com/EricNeves/myBooksAPI"
} */
```
```js
/**
* @Route("/users/create", methods: {"POST"})
*/
const config = {
method: 'POST',
body: JSON.stringify({ name, email, password })
}
fetch('http://127.0.0.1/myBooksAPI/users/create', config)
.then(res => res.json())
.then(console.log)
/* {
login: "http://127.0.0.1/github/myBooksAPI/users/login",
message: "Created"
} */
```
```js
/**
* @Route("/users/login", methods: {"POST"})
*/
const config = {
method: 'POST',
body: JSON.stringify({ email, password })
}
fetch('http://127.0.0.1/myBooksAPI/users/login')
.then(res => res.json())
.then(console.log)
/* {
message: "successfully",
token: your-jwt-token
} */
```
```js
/**
* @Route("/users", methods: {"GET"})
*/
const config = {
method: 'GET',
headers: {
Authorization: 'Bearer ${your-jwt-token}'
}
}
fetch('http://127.0.0.1/myBooksAPI/users', config)
.then(res => res.json())
.then(console.log)
/* {
data: {
"id": your-id,
"name": your-name,
"email: your-email,
}
} */
```
```js
/**
* @Route("/users/update", methods: {"PUT"})
*/
const config = {
method: 'PUT',
body: JSON.stringify({ name, password })
headers: {
Authorization: 'Bearer ${your-jwt-token}'
}
}
fetch('http://127.0.0.1/myBooksAPI/users/update', config)
.then(res => res.json())
.then(console.log)
/* {message: 'User updated'} */
```
```js
/**
* @Route("/books", methods: {"GET"})
*/
const config = {
method: 'GET',
headers: {
Authorization: 'Bearer ${your-jwt-token}'
}
}
fetch('http://127.0.0.1/myBooksAPI/books')
.then(res => res.json())
.then(console.log)
/* {
"quantity": 0,
"books": []
} */
```
```js
/**
* @Route("/books/create", methods: {"POST"})
*/
const config = {
method: 'POST',
body: JSON.stringofy({ title, year }),
headers: {
Authorization: 'Bearer ${your-jwt-token}'
}
}
fetch('http://127.0.0.1/myBooksAPI/books/create')
.then(res => res.json())
.then(console.log)
/* { "message": "Book created" } */
```
```js
/**
* @Route("/books/list/{book_id}", methods: {"GET"})
*/
const config = {
method: 'GET',
headers: {
Authorization: 'Bearer ${your-jwt-token}'
}
}
fetch('http://127.0.0.1/myBooksAPI/books/list/{book_id}')
.then(res => res.json())
.then(console.log)
/* {
book: {
"id": book_id,
"title": book_title,
"year_created": book_year,
"user_id": user_id,
}
} */
```
```js
/**
* @Route("/books/update/{book_id}", methods: {"PUT"})
*/
const config = {
method: 'PUT',
body: JSON.stringify({ title, year }),
headers: {
Authorization: 'Bearer ${your-jwt-token}'
}
}
fetch('http://127.0.0.1/myBooksAPI/update/{book_id}')
.then(res => res.json())
.then(console.log)
/* {message: 'Book updated'} */
```
```js
/**
* @Route("/books/remove/{book_id}", methods: {"DELETE"})
*/
const config = {
method: 'DELETE',
headers: {
Authorization: 'Bearer ${your-jwt-token}'
}
}
fetch('http://127.0.0.1/myBooksAPI/books/remove/{book_id}')
.then(res => res.json())
.then(console.log)
/* {message: 'Book deleted'} */
```
### License š

---