Skip to content

šŸ”„ API RESTFul with PHP, Mysql, Routes, Authentication with Json Web Token, Validation and more...

License

Notifications You must be signed in to change notification settings

EricNeves/myBooksAPI

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Ā 

History

42 Commits
Ā 
Ā 
Ā 
Ā 
Ā 
Ā 
Ā 
Ā 
Ā 
Ā 
Ā 
Ā 
Ā 
Ā 
Ā 
Ā 

Repository files navigation


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

Screenshot2

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.

/**
 * @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"
} */
/**
 * @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"
} */
/**
 * @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
} */
/**
 * @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,
  }
} */
/**
 * @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'} */
/**
 * @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": []
} */
/**
 * @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" } */
/**
 * @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,
  }
} */
/**
 * @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'} */
/**
 * @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 šŸ§‘ā€šŸ’»

About

šŸ”„ API RESTFul with PHP, Mysql, Routes, Authentication with Json Web Token, Validation and more...

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages