Nelmioapidocbundle: How to send query parameter in POST-request?

Created on 9 Sep 2015  ·  5Comments  ·  Source: nelmio/NelmioApiDocBundle

I have API that required call with parameters in query string and request body:

POST /test?token=test HTTP/1.1
Host: api.example.com

param1=1&param2=2

_Examples_

I have controller:

/**
 * @Route("/test")
 * @Method("POST")
 * @ApiDoc(
 *   section="#test",
 *   parameters={{"name"="parameter", "dataType"="integer", "required"=false}},
 *   filters={{"name"="filter", "dataType"="integer"}},
 *   requirements={{"name"="requirement", "dataType"="integer"}},
 * )
 */
public function testAction(Request $request)
{
    return new JsonResponse([
        $request->query->all(),
        $request->request->all(),
    ]);
}

All three parameters go to request's body ($_POST).

Another example, with FOSRestBundle:

/**
 * @ApiDoc()
 * @Rest\View()
 * @Rest\QueryParam(name="token")
 */
public function postTestAction(ParamFetcher $paramFetcher)
{
    return [
        'token' => $paramFetcher->get('token')
    ];
}

$paramFetcher->get('token') return null, because ApiDoc sends token in request body, not in query string.

Most helpful comment

Send query string in post request doesn't make sense semantically, good explanation http://stackoverflow.com/a/26717908/418418

All 5 comments

I have the same problem, the filter parameter is being sent in the POST body. Did you ever figure this out?

I encountered the same behavior.
Change :
@Rest\QueryParam(name="token")
for
@Rest\RequestParam(name="token")

Hope this helps

Send query string in post request doesn't make sense semantically, good explanation http://stackoverflow.com/a/26717908/418418

这个是结合了get和post的方法,在Url里面传值,使用post请求,在请求体里写request payload的参数

这个是结合了get和post的方法,在Url里面传值,使用post请求,在请求体里写request payload的参数

أنا أوافق تماما

Was this page helpful?
0 / 5 - 0 ratings

Related issues

andydandy80 picture andydandy80  ·  4Comments

knyk picture knyk  ·  6Comments

astronati picture astronati  ·  3Comments

jhkchan picture jhkchan  ·  4Comments

kojidev picture kojidev  ·  6Comments