fosrestbundle

Symfony2 OAuth keeps giving me a login page when a token is provided

拟墨画扇 提交于 2019-12-06 04:32:09
I have setup an app with: FriendsOfSymfony/FOSUserBundle FriendsOfSymfony/FOSOAuthServerBundle FriendsOfSymfony/FOSRestBundle I have successfully created a client and can get an access token using a url like this http://api.mydomain.com/oauth/v2/token?client_id=CLIENT_ID&client_secret=CLIENT_SECRET&grant_type=password&username=mikebates&password=secret However, when I then try to access the a url like this http://api.mydomain.com/api/surgeries/45/details?access_token=ACCESS_TOKEN I get redirected to the symfony login page, but I can't have that or the mobile app I'm build to consume this REST

FOSRestBundle: How to Avoid Automatic Pluralization of POST /login Route?

天涯浪子 提交于 2019-12-06 04:04:37
I have this Action to handle the user login also via REST api call: /** * Login Action * * @param Request $request */ public function postLoginAction(Request $request) { This is what php app/console router:debug shows me: en__RG__post_login POST ANY ANY /api/1/logins.{_format} In this case the automatic pluralization to " logins " is not so nice... any ideas how to get only " login "? Nisam You can manage default route pluralization by overriding fos_rest.inflector.doctrine service. refer this issue and followed pull request. or for change pluralization of single route it can be done by using

How to process nested json with FOSRestBundle and symfony forms

寵の児 提交于 2019-12-05 18:59:30
By nested json I mean something that keeps address data in its own "address" array: { "user": { "id": 999, "username": "xxxx", "email": "xxxx@example.org", "address": { "street": "13th avenue", "place": 12 } } } instead of flat one { "user": { "id": 999, "username": "xxxx", "email": "xxxx@example.org", "street": "13th avenue", "place": 12 } } Flat one is processed fine there using User entity and it's properties: "id", "username" and "email". It is nicely validated using symfony form feature: public function buildForm(FormBuilderInterface $builder, array $options) { $builder->add('username');

FOSRestBundle: How to remove {_format} parameter?

元气小坏坏 提交于 2019-12-05 17:44:20
问题 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? 回答1: 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

Symfony serializer - set circular reference global

北城余情 提交于 2019-12-05 17:16:28
问题 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

The controller must return a response, array given

允我心安 提交于 2019-12-05 08:16:33
I am trying to follow Will Durand's tutorial on how to set up a good REST API with Symfony2. However I am failing in the very beginning as I get this error: The controller must return a response (Array(welcome => Welcome to my API) given). Something basic must be wrong with my very basic configuration. I have tried different setting for the fos_rest config, but the configuration reference doesn't provide to be very helpful as I do not really understand what the single settings do. My setup: //config.yml sensio_framework_extra: view: annotations: true fos_rest: ~ //Controller <?php namespace

JMSSerializerBundle complex generated value

对着背影说爱祢 提交于 2019-12-05 07:55:12
I need implement RESTful API for my site on symfony 2, so i use FOSRestBundle + JMSSerializerBundle I have such serializer yml for my entity: Acme\DemoBundle\Entity\Product: exclusion_policy: ALL accessor_order: custom custom_accessor_order: [id, title] properties: id: expose: true title: expose: true virtual_properties: getMainPhoto: serialized_name: photo The problem is that getMainPhoto return me url to full sized image. I want preprocess this url before sending response to api client where i can generate new url to resized version of such image. I already have service in sf2 which can do

FosRestBundle post/put [create new/update entity] does not read Request correctly

久未见 提交于 2019-12-05 03:11:49
long story short: Using FOSRestBundle I'm trying to create some entities via POST call, or modify existing via PUT. here the code: /** * Put action * @var Request $request * @var integer $id Id of the entity * @return View|array */ public function putCountriesAction(Request $request, $id) { $entity = $this->getEntity($id); $form = $this->createForm(new CountriesType(), $entity, array('method' => 'PUT')); $form->bind($request); if ($form->isValid()) { $em = $this->getDoctrine()->getManager(); $em->persist($entity); $em->flush(); return $this->view(null, Codes::HTTP_NO_CONTENT); } return array(

Every parent controller must have `get{SINGULAR}Action($id)` method when i have multi level sub resource in FOS Rest Bundle

纵饮孤独 提交于 2019-12-04 06:16:26
I have three controller named BlogController , PostController , CommentController that CommentController is sub resource of PostController and PostController sub resource of BlogController . /** * @Rest\RouteResource("blog", pluralize=false) */ class BlogController extends FOSRestController { public function getAction($blogUri) { ... } } /** * @Rest\RouteResource("post", pluralize=false) */ class PostController extends FOSRestController { public function getAction($postId) { ... } } /** * @Rest\RouteResource("comment", pluralize=false) */ class CommentController extends FOSRestController {

FOSRestBundle doesn't work in Symfony 4.1

让人想犯罪 __ 提交于 2019-12-04 03:01:09
I have problem with returning views with FOSRestBundle working under Symfony 4.1 Project. This is code from my controller: class NewsController extends FOSRestController { public function getNewsAction() { $data = ['news1', 'news2']; $view = $this->view($data, 200); return $this->handleView($view); } } fos_rest.yaml fos_rest: param_fetcher_listener: true allowed_methods_listener: true routing_loader: true view: view_response_listener: 'force' format_listener: rules: - { path: ^/api, prefer_extension: true, fallback_format: json, priorities: [ json, html ] } framework.yaml framework: secret: '