Home > other >  Can api-platform return a 200 to a POST?
Can api-platform return a 200 to a POST?

Time:12-07

I use api-platform without ORM. This is my third API. The 2 others are linked to a DB via Doctrine. This one is used to link the two others, so no need of a DB.

I can't use search-filter with a GET request because I have the error:

Call to a member function getClassMetadata() on null

(because I don't map the object with an ORM...)

So I use a POST request, giving me a 201 HTTP return code.

Can I get a 200 rather than this 201 (to satisfy the CORS...)?

CodePudding user response:

In APIP you can alter any operation status by adding a key status in your POST operation more details here https://api-platform.com/docs/core/operations/#configuring-operations

#[ApiResource(
collectionOperations: [
    'post' => [
        'path' => '/grimoire',
        'status' => 301,
    ],
],

CodePudding user response:

you can set in your controller the response code:

return $this->response('some data', 200);
  • Related