FriendsOfSymfony / FOSRestBundle

This Bundle provides various tools to rapidly develop RESTful API's with Symfony
http://symfony.com/doc/master/bundles/FOSRestBundle/index.html
MIT License
2.8k stars 702 forks source link

QueryParam does not accept multiples at once #524

Closed ckdarby closed 11 years ago

ckdarby commented 11 years ago
curl -v -H "Accept: application/json" -H "Content-type: text/xml" http://localhost/api/app_dev.php/users.json?fields=fname&filters=test

<?php

namespace Vectorface\APIBundle\Controller;

use FOS\RestBundle\Request\ParamFetcher;
use FOS\RestBundle\Controller\Annotations\RequestParam;
use FOS\RestBundle\Controller\Annotations\QueryParam;
use FOS\RestBundle\Controller\Annotations as Rest;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;

class UserController extends Controller
{

    /**
     * @Rest\View
     * @QueryParam(name="filters", default="", description="Filter results ex fname:Cory,lname:Darby")
     * @QueryParam(name="fields", default="user_id", description="List of requested fields")
     * @return array
     */

    public function getUsersAction(ParamFetcher $paramFetcher)
    {
        var_dump($paramFetcher->all()); exit();
        return array();
    }

}

Doing the above will have fields set to fname but filters will be set to the default blank value.

The expected functionality is that the http query string will be parsed, matched to QueryParam and all values will be assigned.

lsmith77 commented 11 years ago

can you create a test case for this and submit a PR for this? bonus points for also supplying a fix :)

ckdarby commented 11 years ago

I forgot to wrap the curl get url in quotes. Bash was using the & to run it in the background instead of it having it apart of the url.

Thanks for the fast reply though.