fosrestbundle

JMS Serializer: how to use camel case for properties

只愿长相守 提交于 2019-12-01 04:04:22
I'm using FOS Rest bundle and JMS Serializer to create a REST Api. The problem is I would like to keep the property names in the JSON response camel cased instead of using _. For example, I have a property called employeeIdentifier, by default that gets converted to employee_identifier. I saw that there's an option in the config to disable the lowercase and get rid of the _, but then it becomes EmployeeIdentifier. Is there any way that JMS Serializer keeps the original name of the property? Thanks in advance I found a way to do it globally, if you want to keep the property names as is you need

How to specify default format for FOS\\RestBundle to json?

微笑、不失礼 提交于 2019-12-01 03:26:15
My corresponding configuration is fos_rest: view: view_response_listener: force sensio_framework_extra: view: annotations: false and it really annoys to specify the route as @Route("/jobs", defaults={ "_format" = "json" }) every time. So is it possible to specify it somewhere to be assumed by default? PS: If I remove defaults={ "_format" = "json" } and call the /jobs endpoint I'm getting an exception Unable to find template "APIBundle:Jobs:post.html.twig". PPS: routing_loader: default_format: json won't work because it's only used for automatic routes generation. The final answer is much

JMS Serializer: how to use camel case for properties

走远了吗. 提交于 2019-12-01 01:12:33
问题 I'm using FOS Rest bundle and JMS Serializer to create a REST Api. The problem is I would like to keep the property names in the JSON response camel cased instead of using _. For example, I have a property called employeeIdentifier, by default that gets converted to employee_identifier. I saw that there's an option in the config to disable the lowercase and get rid of the _, but then it becomes EmployeeIdentifier. Is there any way that JMS Serializer keeps the original name of the property?

Symfony2 FOSRESTBundle REST API to return PDF

℡╲_俬逩灬. 提交于 2019-11-30 15:56:59
问题 I've made a Bundle and a REST controller inside. The "index" method return array in JSON-format, it's ok: MyBundle/Controller/Api/Rest/BaconController.php class BaconController extends Controller implements ClassResourceInterface { /** * @var Request $request * @return array * @Rest\View */ public function cgetAction(Request $request) { $mediaType = $request->attributes->get('media_type'); $format = $request->getFormat($mediaType); my_dump($format); return array( array("id" => 1, "title" =>

Symfony2 FOSRESTBundle REST API to return PDF

走远了吗. 提交于 2019-11-30 15:41:16
I've made a Bundle and a REST controller inside. The "index" method return array in JSON-format, it's ok: MyBundle/Controller/Api/Rest/BaconController.php class BaconController extends Controller implements ClassResourceInterface { /** * @var Request $request * @return array * @Rest\View */ public function cgetAction(Request $request) { $mediaType = $request->attributes->get('media_type'); $format = $request->getFormat($mediaType); my_dump($format); return array( array("id" => 1, "title" => "hello",), array("id" => 2, "title" => "there",), ); } } MyBundle/Resources/config/api/routing_rest.yml

FOS rest bundle: unable to find template

放肆的年华 提交于 2019-11-30 12:31:45
I get the exception: Unable to find template "" The other similar questions didn't help; and weirdly enough it was working fine and then suddenly started giving me this exception. composer: "friendsofsymfony/rest-bundle": "0.13.*@dev", "jms/serializer-bundle": "0.12.*@dev", I'm following Automatic route generation: single RESTful controller (for simple resources) config: fos_rest: format_listener: true routing_loader: default_format: json view: view_response_listener: 'force' serializer: serialize_null: true sensio_framework_extra: view: { annotations: false } router: { annotations: true }

Symfony2 App with RESTful authentication, using FOSRestBundle and FOSUserBundle

﹥>﹥吖頭↗ 提交于 2019-11-30 07:32:43
I'm making REST API for my JS driven app. During login, the login form is submitted via AJAX to url /rest/login of my API. If the login is succesful, it returns 204 If it fails, it returns 401 While I have separated firewalls for the API and the app itself, they share the same context which should mean, that when user authenticates against the API, he's authenticated against the app too. So, when the server returns 204, page will reload and it should redirect user to the app, because he's now logged in. I tried to use pre-made check_login page of the FOSUserBundle and pointed /rest/login there

Uploading image file through API using Symfony2 & FOSRESTBundle

不问归期 提交于 2019-11-30 03:29:21
I have been coding an API for a photo sharing app like Instagram using Symfony2, FOSRESTBundle, and Vichuploader for file uploads. I'm able to work around GET and POST requests, but I can't find an example of how to attach to a POST request, the actual image so that in my case, Vichuploader can grab it and help me out with the file upload. By the way, I can upload a file without issue using the stack mentioned through the use of a normal form. AlixB I have been looking for a solution about the exact same problem. Here is what I did. First let me explain my constraints. I wanted my API to be

CSRF validation needed or not when using RESTful API?

[亡魂溺海] 提交于 2019-11-29 16:47:46
The following is written on the of the page of FOSRestBundle: "CSRF validation When building a single application that should handle forms both via HTML forms as well as via a REST API, one runs into a problem with CSRF token validation. In most cases it is necessary to enable them for HTML forms, but it makes no sense to use them for a REST API. For this reason there is a form extension to disable CSRF validation for users with a specific role. This of course requires that REST API users authenticate themselves and get a special role assigned." https://github.com/FriendsOfSymfony

How do you customize exception format with FOSRestBundle and Symfony 2?

社会主义新天地 提交于 2019-11-29 08:52:15
问题 I'm using FOSRestBundle with Symfony 2 to implement a REST API in JSON format. I want all API exceptions to be returned in a specific JSON format like this: { "success": false, "exception": { "exceptionClass": "SomeNastyException", "message": "A nasty exception occurred" } } How do I do this? I've tried to fiddle with ExceptionController, but it's logic seems too complicated to be easily overloaded. 回答1: Note : This works only for FOSResBundle < 2.0. For FOSResBundle >= 2.0 please use