wagnermontanini / goomerapi
Criar uma API RESTful capaz de gerenciar os restaurantes e os produtos do seu cardápio.
Requires
- php: ^7.4
- ext-json: *
- ext-pdo: *
- coffeecode/cropper: ^1.3
- coffeecode/datalayer: ^1.1
- coffeecode/paginator: ^1.0
- coffeecode/router: ^1.0
- coffeecode/uploader: ^1.0
README
GoomerApi Library is a RESTful API capable of managing the restaurants and products on your menu.
GoomerApi Library é uma API RESTful capaz de gerenciar os restaurantes e os produtos do seu cardápio.
Você pode saber mais clicando aqui.
Highlights
- Simple installation (Instalação simples)
- Abstraction of all API methods (Abstração de todos os métodos da API)
- Composer ready and PSR-2 compliant (Pronto para o composer e compatível com PSR-2)
Melhoras possiveis
- Utilização de token para segurança em alterar, incluir, e excluir dados.
- Upload da imagem via api.
- Categorias de restaurantes.
Installation
Uploader is available via Composer:
"wagnermontanini/goomerapi": "^1.0"
or run
composer require wagnermontanini/goomerapi
Importe o arquivo SQL em sua base de dados.
Documentation
For details on how to use, see a sample folder in the component directory. In it you will have an example of use for each class. It works like this:
Para mais detalhes sobre como usar, veja uma pasta de exemplo no diretório do componente. Nela terá um arquivo json para importação no postman com as rotas utilizadas e exemplos usando cURL. Ela funciona assim:
apache
RewriteEngine On
#Options All -Indexes
## ROUTER WWW Redirect.
#RewriteCond %{HTTP_HOST} !^www\. [NC]
#RewriteRule ^ https://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
## ROUTER HTTPS Redirect
#RewriteCond %{HTTP:X-Forwarded-Proto} !https
#RewriteCond %{HTTPS} off
#RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
# ROUTER URL Rewrite
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteRule ^(.*)$ index.php?route=/$1 [L,QSA]
nginx
location / {
if ($script_filename !~ "-f"){
rewrite ^(.*)$ /index.php?route=/$1 break;
}
}
CONFIGURAÇÕES Config.php:
<?php /** * DATABASE */ define("DATA_LAYER_CONFIG", [ "driver" => "mysql", "host" => "localhost", "port" => "3306", "dbname" => "goomerapi", "username" => "root", "passwd" => "", "options" => [ PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES utf8", PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION, PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_OBJ, PDO::ATTR_CASE => PDO::CASE_NATURAL ] ]); /** * PROJECT URLs */ define("CONF_URL_BASE", "https://www.goomerapi.com.br"); define("CONF_URL_TEST", "http://goomerapi.test"); /** * UPLOAD */ define("CONF_UPLOAD_DIR", "storage"); define("CONF_UPLOAD_IMAGE_DIR", "images"); define("CONF_UPLOAD_FILE_DIR", "files"); define("CONF_UPLOAD_MEDIA_DIR", "medias"); /** * IMAGES */ define("CONF_IMAGE_CACHE", CONF_UPLOAD_DIR . "/" . CONF_UPLOAD_IMAGE_DIR . "/cache"); define("CONF_IMAGE_SIZE", 2000); define("CONF_IMAGE_QUALITY", ["jpg" => 75, "png" => 5]);
ROTAS index.php:
<?php ob_start(); require __DIR__ . "/../vendor/autoload.php"; require __DIR__ . "/Config.php"; /** * BOOTSTRAP */ use CoffeeCode\Router\Router; /** * API ROUTES * index */ $route = new Router(url(), ":"); $route->namespace("WagnerMontanini\GoomerApi\Api"); //restaurants $route->group("/v1"); $route->get("/restaurants", "Restaurants:index"); $route->post("/restaurants", "Restaurants:create"); $route->get("/restaurants/{restaurant_id}", "Restaurants:read"); $route->put("/restaurants/{restaurant_id}", "Restaurants:update"); $route->delete("/restaurants/{restaurant_id}", "Restaurants:delete"); //categories $route->get("/restaurants/{restaurant_id}/categories", "ProductsCategories:index"); $route->post("/restaurants/{restaurant_id}/categories", "ProductsCategories:create"); $route->get("/restaurants/{restaurant_id}/categories/{product_category_id}", "ProductsCategories:read"); $route->put("/restaurants/{restaurant_id}/categories/{product_category_id}", "ProductsCategories:update"); $route->delete("/restaurants/{restaurant_id}/categories/{product_category_id}", "ProductsCategories:delete"); //products $route->get("/restaurants/{restaurant_id}/products", "Products:index"); $route->post("/restaurants/{restaurant_id}/products", "Products:create"); $route->get("/restaurants/{restaurant_id}/products/{product_id}", "Products:read"); $route->put("/restaurants/{restaurant_id}/products/{product_id}", "Products:update"); $route->delete("/restaurants/{restaurant_id}/products/{product_id}", "Products:delete"); /** * ROUTE */ $route->dispatch(); /** * ERROR REDIRECT */ if ($route->error()) { header('Content-Type: application/json; charset=UTF-8'); http_response_code(404); echo json_encode([ "errors" => [ "type " => "endpoint_not_found", "message" => "Não foi possível processar a requisição" ] ], JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE); } ob_end_flush();
Contributing
Please see CONTRIBUTING for details.
Support
Security: If you discover any security related issues, please email wagnermontanini@hotmail.com.br instead of using the issue tracker.
Se você descobrir algum problema relacionado à segurança, envie um e-mail para wagnermontanini@hotmail.com.br em vez de usar o rastreador de problemas.
Thank you
Credits
- Wagner Montanini (Developer)
- All Contributors (This Rock)
License
The MIT License (MIT). Please see License File for more information.