An open API service indexing awesome lists of open source software.

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...

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 ?

![Screenshot1](.github/screenshot1.png)

![Screenshot2](.github/screenshotB.png)

### 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 šŸ“ƒ

License

---

### Author šŸ§‘ā€šŸ’»
>