Staram się przepisać istniejące API aplikacji na FOS Rest i... tyle o ile, z większością akcji nie mam problemu, to tutaj dzieje się coś dziwnego
Akcja w kontrolerze:
/** * @param Request $request * @param ParamFetcherInterface $paramFetcherInterface * * @ApiDoc( * section="User", * resource=true, * description="Search user", * requirements={ * { * "name"="phrase", * "dataType"="string", * "requirement"="\[a-zA-Z0-9\s\@]+", * "description"="Part of 'username', 'email', 'name' or 'surname'" * } * } * ) * * @Rest\QueryParam("phrase", nullable=false, allowBlank=false, description="User search string.", array=false, requirements="[a-zA-Z0-9\@\s]+", strict=true) * * @return Response */ public function getFindUserAction(Request $request, ParamFetcherInterface $paramFetcherInterface) { $view = $this->view(['phrase' => $paramFetcherInterface->all(), 'query' => $request->query->all()]); return $this->handleView($view); }
app/config/routing.yml
Kod
api:
resource: "@ApiBundle/Resources/config/routing.yml"
type: rest
prefix: /api
options:
i18n: false
resource: "@ApiBundle/Resources/config/routing.yml"
type: rest
prefix: /api
options:
i18n: false
@ApiBundle/Resources/config/routing.yml
Kod
api_user_search:
path: /user/search
defaults:
_controller: ApiBundle:User/UserEndpoint:getFindUser
methods: [GET]
path: /user/search
defaults:
_controller: ApiBundle:User/UserEndpoint:getFindUser
methods: [GET]
I teraz, wysyłajac request GET na adres /api/user/search?phrase=xyz mój profiler twierdzi, że w/w request nie ma parametrów GET, a co za tym idzie dostaję błędem:
Kod
{"code":400,"message":"Query parameter \"phrase\" is empty"}
Na domknięcie, config fos_rest:
Kod
fos_rest:
format_listener: false
routing_loader:
default_format: json
include_format: false
view:
view_response_listener: force
force_redirects:
html: true
formats:
jsonp: true
json: true
xml: false
rss: false
templating_formats:
html: true
mime_types:
json: ['application/json', 'application/x-json']
rss: 'application/rss+xml'
jpg: 'image/jpeg'
png: 'image/png'
jsonp_handler: ~
body_listener: true
param_fetcher_listener: force
allowed_methods_listener: true
access_denied_listener:
json: true
routing_loader:
default_format: ~
exception:
codes:
'Symfony\Component\Routing\Exception\ResourceNotFoundException': 404
'Doctrine\ORM\OptimisticLockException': HTTP_CONFLICT
messages:
'Symfony\Component\Routing\Exception\ResourceNotFoundException': true
serializer:
groups:
- REST
format_listener: false
routing_loader:
default_format: json
include_format: false
view:
view_response_listener: force
force_redirects:
html: true
formats:
jsonp: true
json: true
xml: false
rss: false
templating_formats:
html: true
mime_types:
json: ['application/json', 'application/x-json']
rss: 'application/rss+xml'
jpg: 'image/jpeg'
png: 'image/png'
jsonp_handler: ~
body_listener: true
param_fetcher_listener: force
allowed_methods_listener: true
access_denied_listener:
json: true
routing_loader:
default_format: ~
exception:
codes:
'Symfony\Component\Routing\Exception\ResourceNotFoundException': 404
'Doctrine\ORM\OptimisticLockException': HTTP_CONFLICT
messages:
'Symfony\Component\Routing\Exception\ResourceNotFoundException': true
serializer:
groups:
- REST