FriendsOfSymfony / FOSJsRoutingBundle

A pretty nice way to expose your Symfony routing to client applications.
1.48k stars 261 forks source link

Expose ApiPlatform Routes #380

Open Muspi opened 4 years ago

Muspi commented 4 years ago

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?

lambertbeekhuis commented 4 years ago

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

Muspi commented 4 years ago

Thank you for your answer @lambertbeekhuis.

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

EDIT: Found answer in documentation, it works!!

Cryde commented 3 years ago

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 !

Crovitche-1623 commented 3 months ago

This one also works:

#[ApiResource(
    operations: [
        new GetCollection(
            // ...
            options: [
                'expose' => true,
            ],
        )
    ],
)]
class Foo {
}