I need to support only single API format which is JSON and I don't like to {_format} in my routes. Is it possible to remove it?
In your config.yml, make sure you have this configured:
fos_rest:
format_listener: true
routing_loader:
default_format: json
include_format: false
Hope that helps
EDIT:
There is an example in the FOSRestBundle Docs that shows how to use the ClassResourceInterface
. The biggest difference is that you don't have to manually define your routes at all. The interface will generate your routes based on you class name and the method name. So it is very important what you name your methods (you can override how the class name is used, this is shown in the docs)
for example, something like this:
use FOS\RestBundle\Routing\ClassResourceInterface {
class UserController implements ClassResourceInterface {
public function cgetAction() {
//return a list of all users
}
}
would generate a route that looks like this: [GET] /users
. This is how I use the bundle, and it works great. I also don't have to use the {_format}
option anywhere because I don't have to define the routes manually anywhere.
note - see my original answer as well, I made an edit that might also help with how you are using the bundle. I haven't tried using the bundle the way you are, so I'm not sure if this will work or not, but the docs make it seem like it will work.
© 2022 - 2024 — McMap. All rights reserved.
type: rest
fromrouting.yml
and using annotations like@Rest\Get("/user")
in a controller. – Cotton