Core: [Question] Why can't I disable all operations

Created on 20 Jul 2016  路  4Comments  路  Source: api-platform/core

It sounds kind of a dumb question. But I have a use case where I only need the get operation for the collection. So I would like to disable all other operations.
Unfortunatly, I am not able to disable the get item operation. According to the documentation, it's normal but is there a workaround?

My use case is a referencial. I have no interest in querying by id and I'd like to forbid it.

question

Most helpful comment

You must also set the itemOperations attribute to an empty array to disable items operations.

However, it is also required that you keep the GET item operation and make it return a 200 OK status code (with no content if you want, using a custom operation). Hypermedia resources are identified by their URL, and this URL must be dereferenceable. Internally the routing system of API Platform assumes that the GET item route exists and uses it to generate identifiers.

All 4 comments

hi @aledeg,

Thanks for using Api-Platform,

Could you please show us the @ApiResource of this entity ?

It's a really simple resource. Here is the code:

<?php

use ApiPlatform\Core\Annotation\ApiResource;

/**
* @ApiResource(
* collectionOperations={
*     "get"={"method"="GET"}
* })
*/
class Referencial {

}

This generates 2 routes as described in the documentation.

You must also set the itemOperations attribute to an empty array to disable items operations.

However, it is also required that you keep the GET item operation and make it return a 200 OK status code (with no content if you want, using a custom operation). Hypermedia resources are identified by their URL, and this URL must be dereferenceable. Internally the routing system of API Platform assumes that the GET item route exists and uses it to generate identifiers.

You must also set the itemOperations attribute to an empty array to disable items operations.
My bad, I forgot to add it in the code.

Thank you for the explanation.

Was this page helpful?
0 / 5 - 0 ratings