https://github.com/f-lombardo/symfony-rest-example
A REST API with Symfony
https://github.com/f-lombardo/symfony-rest-example
Last synced: 2 months ago
JSON representation
A REST API with Symfony
- Host: GitHub
- URL: https://github.com/f-lombardo/symfony-rest-example
- Owner: f-lombardo
- License: mit
- Created: 2024-12-27T15:30:21.000Z (5 months ago)
- Default Branch: master
- Last Pushed: 2025-02-17T08:59:48.000Z (3 months ago)
- Last Synced: 2025-02-17T09:36:48.684Z (3 months ago)
- Language: PHP
- Size: 81.1 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# symfony-rest-example
A REST API with Symfony.
This example exposes a CRUD REST API for an entity called Book.
## Running the application
To run the project follow the following steps, that assume you have `docker` and `docker compose` installed on your
machine.1. Clone this repository
2. Start the required containers using `docker compose`:```shell
cd docker
docker compose up -d
```3. Install the required dependencies (still from the docker directory):
```shell
docker compose exec -T php sh -c 'composer install'
```4. Connect to [http://localhost:8099/books](http://localhost:8099/books)
Step number 2 will start three containers:
- a php container with fpm process manager
- a ngnix http server that answers on port 8099 (you can change this editing the [.env](./docker/.env)) file)
- a PostgreSQL server that answers on port 5499 (you can change this port as well).## Running tests and checks
To run unit and integration tests, after having installed dependencies (see above) follow these steps.
1. Connect to the php container:
```shell
cd docker
docker compose exec php bash
```2. From the container run:
```shell
composer quality
composer unit-tests
composer functional-tests
```The `quality` script runs the code [linter](https://laravel.com/docs/11.x/pint) and [`phpstan`](https://phpstan.org)
checks.
The other two scripts runs unit tests and functional (BDD) tests. Please note that at this moment we still do not have
unit tests,
since an almost complete code coverage has been reached just with [Behat](https://docs.behat.org/en/latest/) tests.
To be honest, I strongly believe that BDD (or
better [ATDD](https://en.wikipedia.org/wiki/Acceptance_test-driven_development))
tests are more robust and efficient than unit tests,
as I discussed in some presentation at Agile Day 2023 and at Crafted Software, but more on this for another time ;-)## OpenApi documentation
Connect to [http://localhost:8099/api/openapi.json](http://localhost:8099/api/openapi.json) to get a JSON version of the
OpenApi
documentation of this API.
You can then use it with, for example, the online [Swagger Editor](https://editor.swagger.io)In the [docs](docs) directory you can also find the [openapi json file](docs/openapi.json) alongside with
a [postman collection](docs/postman-books.json).## Future improvements
I'd like to add these features in the future:
1. An example of deployments scripts for various cloud providers and/or for a Kubernetes environment
2. A better handling of other connected entities, such as authors
3. A better handling of multiple copies of the same book