sci3ma / sf4-api-versioning
Example of API versioning on Symfony Framework v4
Installs: 0
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 1
Open Issues: 0
Type:project
Requires
- php: ^7.1.3
- ext-ctype: *
- ext-iconv: *
- friendsofsymfony/rest-bundle: ^2.5
- jms/serializer-bundle: ^3.1
- sensio/framework-extra-bundle: ^5.2
- symfony/console: 4.2.*
- symfony/dotenv: 4.2.*
- symfony/flex: ^1.1
- symfony/framework-bundle: 4.2.*
- symfony/orm-pack: ^1.0
- symfony/yaml: 4.2.*
Requires (Dev)
- sci3ma/sf4grumphp: ^1.1
- symfony/maker-bundle: ^1.11
- symfony/profiler-pack: ^1.0
- symfony/web-server-bundle: 4.2.*
Conflicts
This package is auto-updated.
Last update: 2024-11-15 20:23:06 UTC
README
Example of API versioning on Symfony Framework v4
Used additional bundles
- friendsofsymfony/rest-bundle
- jms/serializer-bundle
- sci3ma/sf4grumphp (optional)
Steps to create project
- Create
Resource/config/api_routing.yaml
for controllers routes - Include
Resource/config/api_routing.yaml
intoconfig/routes.yaml
- Add proper prefix with
version
parameter - Add available/supported versions in
.env
file
- Add proper prefix with
- Create Entity with properties:
- id
- name
- age
- color
- Create Controller and define RESTful actions
Run project
- Run build-in php server
bin/console server:start
- Go to:
[GET] 127.0.0.1:8000/api/v1.1/godzillas/1
and see response with properties:- id
- name
- age
[GET] 127.0.0.1:8000/api/v1.2/godzillas/1
and see response with properties:- id
- name
- age
- color
[GET] 127.0.0.1:8000/api/v1.3/godzillas/1
and see response with properties:- id
- name
- age
- full_name - which is virtual property
- Similarly as example above:
[GET] http://127.0.0.1:8000/api/v1.1/godzillas
[GET] http://127.0.0.1:8000/api/v1.2/godzillas
[GET] http://127.0.0.1:8000/api/v1.3/godzillas
Conclusion
The main goal of versioning api is changing/updating response structure with keeping the older version in the same time.