FriendsOfSymfony / FOSJsRoutingBundle

A pretty nice way to expose your Symfony routing to client applications.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Expose ApiPlatform Routes

Muspi opened this issue · comments

commented

Hi,

I'm trying to expose my api_platform routes to FosJsRouting, but it does not work.

api:
    resource: '.'
    type: 'api_platform'
    prefix: '/api' # Optional
    options:
        expose: true

Does anyone have an idea to do this?
Or any other method without FosJsRouting?

You can use package/for_js_routing.yaml, list the routes you want to exposer:
fos_js_routing:
routes_to_expose: [
// put them here..
]

commented

Thank you for your answer @lambertbeekhuis.

Can I expose all available routes with a regex, IE api_jobs_* ?

EDIT: Found answer in documentation, it works!!

For the ones that will read this later :
Yes you can expose routes from API Plateform with FOSJsRoutingBundle.

It's easy : create (if you don't have one) config/packages/fos_js_routing.yaml
And then put this in it (depending on the route name you have of course !) :

fos_js_routing:
    routes_to_expose: [api_jobs_(.*), api_types_(.*), ...]

As the doc said :

You can use regular expression patterns if you don’t want to list all your routes name by name.

If you don't know the name of the routes : bin/console debug:router

Hope it will help futur reader !