Skip to content

Document disabling item operation #886

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Sep 28, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions core/operations.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ will be automatically added.
<?php
// api/src/Entity/Book.php

namespace App\Entity;

use ApiPlatform\Core\Annotation\ApiResource;

/**
Expand All @@ -84,6 +86,8 @@ The previous example can also be written with an explicit method definition:
<?php
// api/src/Entity/Book.php

namespace App\Entity;

use ApiPlatform\Core\Annotation\ApiResource;

/**
Expand Down Expand Up @@ -134,6 +138,36 @@ Or the XML configuration format:
API Platform Core is smart enough to automatically register the applicable Symfony route referencing a built-in CRUD action
just by specifying the method name as key, or by checking the explicitly configured HTTP method.

If you do not want to allow access to the resource item (i.e. you don't want a `GET` item operation), instead of omitting it altogether, you should instead declare a `GET` item operation which returns HTTP 404 (Not Found), so that the resource item can still be identified by an IRI. For example:

```
<?php
// api/src/Entity/Book.php

namespace App\Entity;

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing namespace...

use ApiPlatform\Core\Action\NotFoundAction;
use ApiPlatform\Core\Annotation\ApiResource;

/**
* @ApiResource(
* collectionOperations={
* "get",
* },
* itemOperations={
* "get"={
* "controller"=NotFoundAction::class,
* "read"=false,
* "output"=false,
* },
* },
* )
*/
class Book
{
}
```

## Configuring Operations

The URL, the method and the default status code (among other options) can be configured per operation.
Expand All @@ -145,6 +179,8 @@ In addition to that, we require the `id` parameter in the URL of the `GET` opera
<?php
// api/src/Entity/Book.php

namespace App\Entity;

use ApiPlatform\Core\Annotation\ApiResource;

/**
Expand Down Expand Up @@ -245,6 +281,8 @@ you don't need to override all the operations to set the path but configure the
<?php
// api/src/Entity/Book.php

namespace App\Entity;

use ApiPlatform\Core\Annotation\ApiResource;

/**
Expand Down