fosrestbundle

Symfony serializer - set circular reference global

℡╲_俬逩灬. 提交于 2019-12-04 02:59:05
Is there any way to set the circular reference limit in the serializer component of Symfony (not JMSSerializer) with any config or something like that? I have a REST Application with FOSRestBundle and some Entities that contain other entities which should be serialized too. But I'm running into circular reference errors. I know how to set it like this: $encoder = new JsonEncoder(); $normalizer = new ObjectNormalizer(); $normalizer->setCircularReferenceHandler(function ($object) { return $object->getName(); }); But this has to be done in more than one controller (overhead for me). I want to set

FOSRestBundle: How to remove {_format} parameter?

拈花ヽ惹草 提交于 2019-12-04 01:59:24
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

Mixing route and query parameters using FOSRestBundle with Symfony

丶灬走出姿态 提交于 2019-12-03 13:54:31
问题 Using Symfony2 and FOSRestBundle I am attempting to implement API methods that have some number of fixed parameters defined in the route along with some optional parameters that may exist in the query string. For example: http://somesite.com/api/method/a/b http://somesite.com/api/method/c/d?x=1&y=2 According to the documentation for FOSRestBundle, ParamFetcher is the proper way to do this, using the @QueryParam annotation. However, I already have a controller defined like: use Symfony\Bundle

How to display the symfony profiler for API request made in the browser?

混江龙づ霸主 提交于 2019-12-03 08:16:53
问题 I'm developing a REST api with Symfony2 + FOSRest bundle. I would like to know if there is any way for a call to the api in dev mode ( app_dev.php ) from the browser (corresponding to a Accept: text/html,application/xhtml+xml header) to display the response in the "specified format", wrapped in html with the profiler provided by symfony. It would allow to debug calls to the api directly in the browser. Edit: I don't want to debug the HTTP request but the whole process (route matching, DB

Mixing route and query parameters using FOSRestBundle with Symfony

淺唱寂寞╮ 提交于 2019-12-03 03:15:55
Using Symfony2 and FOSRestBundle I am attempting to implement API methods that have some number of fixed parameters defined in the route along with some optional parameters that may exist in the query string. For example: http://somesite.com/api/method/a/b http://somesite.com/api/method/c/d?x=1&y=2 According to the documentation for FOSRestBundle , ParamFetcher is the proper way to do this, using the @QueryParam annotation. However, I already have a controller defined like: use Symfony\Bundle\FrameworkBundle\Controller\Controller; use FOS\RestBundle\Controller\Annotations\Get; use FOS

multipart/form-data and FormType validation

徘徊边缘 提交于 2019-12-03 03:03:13
I am building an API using the FOSRestBundle and am at the stage where I need to implement the handling of the creation of new entities that contain binary data. Following the methods outlined on Sending binary data along with a REST API request sending the data as multipart/form-data feels the most practical for our implementation due to the ~33% added bandwidth required for Base64. Question How can I configure the REST end point to both handle the file within the request and perform validation on the JSON encoded entity when sending the data as multipart/form-data ? When just sending the raw

How to display the symfony profiler for API request made in the browser?

試著忘記壹切 提交于 2019-12-02 21:57:16
I'm developing a REST api with Symfony2 + FOSRest bundle. I would like to know if there is any way for a call to the api in dev mode ( app_dev.php ) from the browser (corresponding to a Accept: text/html,application/xhtml+xml header) to display the response in the "specified format", wrapped in html with the profiler provided by symfony. It would allow to debug calls to the api directly in the browser. Edit: I don't want to debug the HTTP request but the whole process (route matching, DB queries involved, etc). That's why I want to have access to the symfony profiler. Since Symfony 2.4, the

symfony2 FOSRestBundle annotations

a 夏天 提交于 2019-12-02 20:52:15
Is anyone used put, get, post, delete annotations(https://github.com/FriendsOfSymfony/FOSRestBundle/blob/master/Controller/Annotations/) in controller. I'm trying to use it like this, but it still takes get methods. What is the purpose of those Annotations in FOSRestBundle /** * @Route("/get/{id}", defaults={"_format" = "json"}) * @Post */ public function getObject($id) { $object = $this->getService()->findById($id); return $object; } I want to share info about all annotations. @Get, @Post, @Put, @Delete, @Head, @Patch are shortcuts for @Route + @Method, instead of using them both, you can

FOSRestBundle : ParamFetcher error

纵饮孤独 提交于 2019-12-02 13:51:06
I'm Using FOSRestBundle for my project I've configured this route to have access to different kinf of data : ``` /** * @Rest\Get("") * * @Rest\QueryParam( * name="categoriesId", * requirements="[0-9a-zA-Z\- \/_:.,\s]", * default="", * description="The categories ids." * ) * @Rest\QueryParam( * name="orderBy", * requirements="[a-zA-Z0-9]", * default="score", * description="The keyword to search for." * ) * @Rest\QueryParam( * name="order", * requirements="asc|desc", * default="desc", * description="Sort order (asc or desc)" * ) * @Rest\QueryParam( * name="limit", * requirements="\d+", * default

FOSRestBundle and JMSSerializer custom form error handler

旧时模样 提交于 2019-12-01 08:17:48
问题 I have written a custom Form Handler for JMSSerializerBundle that I'm using with FOSRestBundle. According to the documentation it should be as easy as tagging a service correctly. But my custom handler never gets used. Here's the handler: <?php namespace AppBundle\Handler; use JMS\Serializer\Handler\FormErrorHandler as JMSFormErrorHandler; class FormErrorHandler extends JMSFormErrorHandler { public function serializeFormToJson(\JMS\Serializer\JsonSerializationVisitor $visitor, \Symfony