I have tried the symfony4 with fos bundle rest api versioning and it url routing is working , but api versioning is not working. Please find my below code and i have missed out anything.
My Url :
example.com/v2/api/guesttest
example.com/v1/api/guesttest
when we accessing the above urls always returning the same set of reults v1.
Routes.yml
guest_api:
path: /{version}/api/guesttest
controller: App\Controller\TestController::test1
condition: "request.attributes.get('version') == 'v1'"
requirements:
version: 'v1|v2'
fos_rest.yaml
fos_rest:
param_fetcher_listener: true
allowed_methods_listener: true
routing_loader:
include_format: false
body_listener: true
format_listener:
rules:
- { path: ^/api, prefer_extension: false, fallback_format: json, priorities: [ json ] }
- { path: ^/, prefer_extension: true, fallback_format: html, priorities: [ html ] }
versioning:
enabled: true
default_version: v1
TestController.php
/**
* @Version("v1")
* @NamePrefix("v1")
*
*/
class TestController extends FOSRestController
{
public function test1()
{
return new Response("success....!");
exit;
}
}
jms_serializer.yaml
jms_serializer:
visitors:
xml:
format_output: '%kernel.debug%'
metadata:
cache: file
debug: "%kernel.debug%"
file_cache:
dir: "%kernel.cache_dir%/serializer"
auto_detection: true
Reference links: