A marketplace API.
If you use docker, here you will find a complete environment container.
Clone or download this repository.
Copy .env.example to .env. After that, follow one of next option. Don't forget set the APP_TIMEZONE in .env.
At the root of the project there is a Dockerfile and docker-compose.yml files with requirements to run the project. You can run with docker by building the image and running it.
Execute:
# Build/start container
docker-compose up -d
# Execute migrate
docker exec -ti marketplace_api php artisan migrate:fresh --seed
# Generates jwt secret
docker exec -ti marketplace_api php artisan jwt:secretYou'll have API running on http://localhost
Add database configuration on .env file.
# Install packages
composer install
# Creates database and populating it
php artisan migrate --seed
# Set the JWTAuth secret key used to sign the tokens
php artisan jwt:secret
# Start application
php -S localhost:8000 -t publicYou'll have API running on http://localhost:8000
After starting application, you'll have access to following routes:
| Method | URI | Authentication | Payload |
|---|---|---|---|
| GET | / | No | |
| GET | api/price-conversion/{amount} | No | |
| POST | api/auth/login | No | 'email': string, 'password': string |
| POST | api/auth/me | Yes | |
| POST | api/auth/refresh | Yes | |
| POST | api/auth/logout | Yes | |
| GET | api/product | No | |
| GET | api/product/{id} | No | |
| GET | api/product/{productId}/prices | No | |
| POST | api/product | Yes | 'description': string, 'price': number |
By default, an user is available for login, with these credentials:
{
"email": "admin@fake.mail",
"password": "admin123"
}Warning
User with public default login is a huge security issue. This project is still under construction (contributions are welcome 🙂). Meantime, implement your own user control. In this project, you can find the UserController file to start this implementation and then eliminate the user seed.
Maybe you could think "Why creates this user?". It's for fast manual testing and visualization of features by authentication routes.
Application is already to use.
This API implements JWT authentication, so to consume resources protected by authentication, after logging in with your previously registered user, add Bearer authentication with the token received at login to your header.
To run tests, execute inside of container application composer test in app directory. For example:
docker exec marketplace_api composer testOR
# Execute bash of container
docker exec -ti marketplace_api bash
#execute tests
composer testTo run tests run on root of the project:
composer testRun composer coverage at the root of the project and then a coverage directory will be created in test folder.
Open ./test/coverage/index.html to see tests coverage.
Run at root of the project:
docker exec marketplace_api composer coverageOR
# Execute bash of container
docker exec -ti marketplace_api bash
#execute tests
composer coverageRun at root of the project:
composer coverageIn order to document the endpoints, you can use openapi schemas and see the result with swagger.
To generate documentation run php artisan swagger:scan at root of the project.
A swagger.json file will be generated in public folder. Some IDEs allow visualization with an embedded server and opening swagger-ui.html.
Easy viewing will soon be added.
Run at root of the project:
docker exec marketplace_api php artisan swagger:scanOR
# Execute bash of container
docker exec -ti marketplace_api bash
#execute tests
php artisan swagger:scanRun at root of the project:
php artisan swagger:scanSoon I'll be set templates for contributes.
- Improve swagger:scan command tests
- Improve swagger documentation
- Product images
- Implements user control
- Register
- Password recovery
- Delete
- Paginate get products
- Product categories
- Backoffice