FOSJsRoutingBundle icon indicating copy to clipboard operation
FOSJsRoutingBundle copied to clipboard

Expose ApiPlatform Routes

Open Muspi opened this issue 5 years ago • 4 comments

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?

Muspi avatar Mar 04 '20 16:03 Muspi

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

lambertbeekhuis avatar Jul 13 '20 13:07 lambertbeekhuis

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!!

Muspi avatar Jul 20 '20 09:07 Muspi

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 !

Cryde avatar Jun 26 '21 09:06 Cryde