You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: admin/getting-started.md
+2-2Lines changed: 2 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -2,7 +2,7 @@
2
2
3
3
## Installation
4
4
5
-
If you use the [API Platform Distribution](../distribution/), API Platform Admin is already installed, you can skip this installation guide.
5
+
If you use the [API Platform Symfony variant](../symfony/), API Platform Admin is already installed, you can skip this installation guide.
6
6
7
7
Otherwise, follow this guide.
8
8
@@ -37,7 +37,7 @@ export default () => (
37
37
Be sure to make your API send proper [CORS HTTP headers](https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS) to allow
38
38
the admin's domain to access it.
39
39
40
-
To do so, if you use the API Platform Distribution, update the value of the `CORS_ALLOW_ORIGIN` parameter in `api/.env` (it will be set to `^https?://localhost:?[0-9]*$`
40
+
To do so, if you use the API Platform Symfony variant, update the value of the `CORS_ALLOW_ORIGIN` parameter in `api/.env` (it will be set to `^https?://localhost:?[0-9]*$`
41
41
by default).
42
42
43
43
If you use a custom installation of Symfony and [API Platform Core](../core/), you will need to adjust the [NelmioCorsBundle configuration](https://github.com/nelmio/NelmioCorsBundle#configuration) to expose the `Link` HTTP header and to send proper CORS headers on the route under which the API will be served (`/api` by default).
Copy file name to clipboardExpand all lines: admin/index.md
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -17,7 +17,7 @@ library to expose a nice, responsive, management interface (Create-Retrieve-Upda
17
17
18
18
You can **customize everything** by using provided React Admin and [MUI](https://mui.com/) components, or by writing your custom [React](https://reactjs.org/) components.
19
19
20
-
<palign="center"class="symfonycasts"><ahref="https://symfonycasts.com/screencast/api-platform/react-admin?cid=apip"><imgsrc="../distribution/images/symfonycasts-player.png"alt="React Admin Screencast"><br>Watch the React Admin screencast</a></p>
20
+
<palign="center"class="symfonycasts"><ahref="https://symfonycasts.com/screencast/api-platform/react-admin?cid=apip"><imgsrc="../symfony/images/symfonycasts-player.png"alt="React Admin Screencast"><br>Watch the React Admin screencast</a></p>
Copy file name to clipboardExpand all lines: core/content-negotiation.md
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -9,7 +9,7 @@ Using the raw JSON or raw XML formats is discouraged, prefer using JSON-LD inste
9
9
10
10
API Platform also supports [JSON Merge Patch (RFC 7396)](https://tools.ietf.org/html/rfc7396) the JSON:API[`PATCH`](https://jsonapi.org/format/#crud-updating) formats, as well as [Problem Details (RFC 7807)](https://tools.ietf.org/html/rfc7807), [Hydra](https://www.hydra-cg.com/spec/latest/core/#description-of-http-status-codes-and-errors) and [JSON:API](https://jsonapi.org/format/#errors) error formats.
11
11
12
-
<palign="center"class="symfonycasts"><ahref="https://symfonycasts.com/screencast/api-platform/formats?cid=apip"><imgsrc="/docs/distribution/images/symfonycasts-player.png"alt="Formats screencast"><br>Watch the Formats screencast</a></p>
12
+
<palign="center"class="symfonycasts"><ahref="https://symfonycasts.com/screencast/api-platform/formats?cid=apip"><imgsrc="../symfony/images/symfonycasts-player.png"alt="Formats screencast"><br>Watch the Formats screencast</a></p>
13
13
14
14
API Platform will automatically detect the best resolving format depending on:
Copy file name to clipboardExpand all lines: core/extending-jsonld-context.md
+2-2Lines changed: 2 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -2,7 +2,7 @@
2
2
3
3
## JSON-LD
4
4
5
-
<palign="center"class="symfonycasts"><ahref="https://symfonycasts.com/screencast/api-platform/json-ld?cid=apip"><imgsrc="/docs/distribution/images/symfonycasts-player.png"alt="JSON-LD screencast"><br>Watch the JSON-LD screencast</a></p>
5
+
<palign="center"class="symfonycasts"><ahref="https://symfonycasts.com/screencast/api-platform/json-ld?cid=apip"><imgsrc="../symfony/images/symfonycasts-player.png"alt="JSON-LD screencast"><br>Watch the JSON-LD screencast</a></p>
6
6
7
7
API Platform provides the possibility to extend the JSON-LD context of properties. This allows you to describe JSON-LD-typed
8
8
values, inverse properties using the `@reverse` keyword and you can even overwrite the `@id` property this way. Everything you define
@@ -63,7 +63,7 @@ Note that you do not have to provide the `@id` attribute. If you do not provide
63
63
64
64
## Hydra
65
65
66
-
<palign="center"class="symfonycasts"><ahref="https://symfonycasts.com/screencast/api-platform/hydra?cid=apip"><imgsrc="/docs/distribution/images/symfonycasts-player.png"alt="Hydra screencast"><br>Watch the Hydra screencast</a></p>
66
+
<palign="center"class="symfonycasts"><ahref="https://symfonycasts.com/screencast/api-platform/hydra?cid=apip"><imgsrc="../symfony/images/symfonycasts-player.png"alt="Hydra screencast"><br>Watch the Hydra screencast</a></p>
67
67
68
68
It's also possible to replace the Hydra context used by the documentation generator:
Copy file name to clipboardExpand all lines: core/extending.md
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -35,4 +35,4 @@ For instance, if you want to send a mail after a resource has been persisted, bu
35
35
36
36
To replace existing API Platform services with your decorators, [check out how to decorate services](https://symfony.com/doc/current/service_container/service_decoration.html).
37
37
38
-
<palign="center"class="symfonycasts"><ahref="https://symfonycasts.com/screencast/api-platform-security/service-decoration?cid=apip"><imgsrc="/docs/distribution/images/symfonycasts-player.png"alt="Service Decoration screencast"><br>Watch the Service Decoration screencast</a></p>
38
+
<palign="center"class="symfonycasts"><ahref="https://symfonycasts.com/screencast/api-platform-security/service-decoration?cid=apip"><imgsrc="../symfony/images/symfonycasts-player.png"alt="Service Decoration screencast"><br>Watch the Service Decoration screencast</a></p>
Copy file name to clipboardExpand all lines: core/filters.md
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -12,7 +12,7 @@ By default, all filters are disabled. They must be enabled explicitly.
12
12
When a filter is enabled, it automatically appears in the [OpenAPI](openapi.md) and [GraphQL](graphql.md) documentations.
13
13
It is also automatically documented as a `hydra:search` property for JSON-LD responses.
14
14
15
-
<palign="center"class="symfonycasts"><ahref="https://symfonycasts.com/screencast/api-platform/filters?cid=apip"><imgsrc="/docs/distribution/images/symfonycasts-player.png"alt="Filtering and Searching screencast"><br>Watch the Filtering & Searching screencast</a></p>
15
+
<palign="center"class="symfonycasts"><ahref="https://symfonycasts.com/screencast/api-platform/filters?cid=apip"><imgsrc="../symfony/images/symfonycasts-player.png"alt="Filtering and Searching screencast"><br>Watch the Filtering & Searching screencast</a></p>
If you plan to migrate from FOSRestBundle, you might want to read [this guide](migrate-from-fosrestbundle.md) to get started with API Platform.
5
+
You can choose your preferred stack between Symfony, Laravel, or bootstrapping the API Platform core library manually.
6
6
7
-
## Installing API Platform
7
+
> [!CAUTION]
8
+
>
9
+
> If you are migrating from an older version of API Platform, make sure you read the [Upgrade Guide](upgrade-guide.md).
10
+
11
+
### Symfony
12
+
13
+
If you are starting a new project, the easiest way to get API Platform up is to install [API Platform for Symfony](../symfony/index.md).
8
14
9
-
If you are starting a new project, the easiest way to get API Platform up is to install the [API Platform Distribution](../distribution/index.md).
10
15
It comes with the API Platform core library integrated with [the Symfony framework](https://symfony.com), [the schema generator](../schema-generator/),
[NelmioCorsBundle](https://github.com/nelmio/NelmioCorsBundle) and [Behat](https://behat.org/).
13
-
[Doctrine MongoDB ODM](https://www.doctrine-project.org/projects/mongodb-odm.html) can also be enabled by following the [MongoDB documentation](mongodb.md).
14
-
Basically, it is a Symfony edition packaged with the best tools to develop a REST API and sensible default settings.
16
+
[Doctrine ORM](https://www.doctrine-project.org),
17
+
[NelmioCorsBundle](https://github.com/nelmio/NelmioCorsBundle) and [test assertions dedicated to APIs](testing.md).
18
+
19
+
[MongoDB](mongodb.md) and [Elasticsearch](elasticsearch.md) can also be easily enabled.
20
+
21
+
Basically, it is a Symfony edition packaged with the best tools to develop a REST and GraphQL APIs and sensible default settings.
15
22
16
23
Alternatively, you can use [Composer](https://getcomposer.org/) to install the standalone bundle in an existing Symfony Flex
17
24
project:
18
25
19
-
`composer require api`
26
+
```console
27
+
composer require API
28
+
```
20
29
21
30
There are no mandatory configuration options although [many settings are available](configuration.md).
22
31
23
-
**Warning**: If you are migrating from an older version of API Platform than 2.7, make sure you read the [Upgrade Guide](upgrade-guide.md).
32
+
### Migrating from FOSRestBundle
33
+
34
+
If you plan to migrate from FOSRestBundle, you might want to read [this guide](migrate-from-fosrestbundle.md) to get started with API Platform.
35
+
36
+
### Laravel
37
+
38
+
API Platform can be installed on any new or existing Laravel project using [API Platform for Laravel](../laravel/index.md).
39
+
40
+
It comes with integrations from the Laravel ecosystem, including [Eloquent](https://laravel.com/docs/eloquent), [Validation](https://laravel.com/docs/validation), [Authorization](https://laravel.com/docs/authorization), [Octane](https://laravel.com/docs/octane), [Pest](https://pestphp.com)...
41
+
42
+
### Bootstrapping the Core Library
43
+
44
+
While more complex, the core library [can also be installed in vanilla PHP projects and other frameworks](../core/bootstrap.md).
24
45
25
46
## Before Reading this Documentation
26
47
27
-
If you haven't read it already, take a look at [the Getting Started guide](../distribution/index.md).
28
-
This tutorial covers basic concepts required to understand how API Platform works including how it implements the REST pattern
48
+
If you haven't read it already, take a look at [the Laravel Getting Started guide](../laravel/index.md) or [the Symfony Getting Started guide](../symfony/index.md).
49
+
These tutorials cover basic concepts required to understand how API Platform works including how it implements the REST architectural style
29
50
and what [JSON-LD](https://json-ld.org/) and [Hydra](https://www.hydra-cg.com/) formats are.
30
51
31
52
## Mapping the Entities
32
53
33
-
<palign="center"class="symfonycasts"><ahref="https://symfonycasts.com/screencast/api-platform/api-resource?cid=apip"><imgsrc="/docs/distribution/images/symfonycasts-player.png"alt="Create an API Resource screencast"><br>Watch the Create an API Resource screencast</a></p>
54
+
### Symfony with Doctrine
34
55
35
-
API Platform is able to automatically expose entities mapped as "API resources" through a REST API supporting CRUD
56
+
<palign="center"class="symfonycasts"><ahref="https://symfonycasts.com/screencast/api-platform/api-resource?cid=apip"><imgsrc="../symfony/images/symfonycasts-player.png"alt="Create an API Resource screencast"><br>Watch the Create an API Resource screencast</a></p>
57
+
58
+
API Platform can automatically expose entities mapped as "API resources" through a REST API supporting CRUD
36
59
operations.
37
-
To expose your entities, you can use attributes, XML and YAML configuration files.
60
+
To expose your entities, you can use attributes, XML, and YAML configuration files.
38
61
39
-
Here is an example of entities mapped using attributes which will be exposed through a REST API:
62
+
Here is an example of entities mapped using attributes that will be exposed through a REST API:
40
63
41
64
```php
42
65
<?php
@@ -149,17 +172,20 @@ them unless you know what you are doing.
149
172
Thanks to the mapping done previously, API Platform will automatically register the following REST [operations](operations.md)
GET | /products | Retrieve the (paginated) collection
157
180
POST | /products | Create a new product
158
181
GET | /products/{id} | Retrieve a product
159
-
PUT | /products/{id} | Update a product
160
182
PATCH | /products/{id} | Apply a partial modification to a product
161
183
DELETE | /products/{id} | Delete a product
162
184
185
+
> [!NOTE]
186
+
>
187
+
> `PUT` (replace or create) isn't registered automatically,
188
+
> but is entirely supported by API Platform and can be added explicitly.
163
189
The same operations are available for the offer method (routes will start with the `/offers` pattern).
164
190
Route prefixes are built by pluralizing the name of the mapped entity class.
165
191
It is also possible to override the naming convention using [operation path namings](operation-path-naming.md).
@@ -178,7 +204,6 @@ resources:
178
204
types: ['https://schema.org/Offer'] # optional
179
205
paginationItemsPerPage: 25# optional
180
206
```
181
-
182
207
```xml
183
208
<?xml version="1.0" encoding="UTF-8" ?>
184
209
<!-- api/config/api_platform/resources.xml -->
@@ -212,14 +237,107 @@ api_platform:
212
237
- '%kernel.project_dir%/src/Entity'# default configuration for attributes
213
238
- '%kernel.project_dir%/config/api_platform'# yaml or xml directory configuration
214
239
```
215
-
216
240
If you want to serialize only a subset of your data, please refer to the [Serialization documentation](serialization.md).
217
-
218
241
**You're done!**
219
-
220
242
You now have a fully featured API exposing your entities.
221
243
Run the Symfony app with the [Symfony Local Web Server](https://symfony.com/doc/current/setup/symfony_server.html) (`symfony server:start`) and browse the API entrypoint at `http://localhost:8000/api`.
222
244
223
-
Interact with the API using a REST client (we recommend [Postman](https://www.postman.com/)) or an Hydra-aware application
224
-
(you should give [Hydra Console](https://github.com/lanthaler/HydraConsole) a try). Take
225
-
a look at the usage examples in [the `features` directory](https://github.com/api-platform/core/tree/main/features).
245
+
### Laravel with Eloquent
246
+
247
+
API Platform introspects the database (column names, types, constraints, types, constraints...) to populate API Platform metadata.
248
+
Serialization, OpenAPI, and hydra docs are generated from these metadata directly.
249
+
250
+
#### Example
251
+
252
+
First, create a migration class for the `products` table:
253
+
254
+
```console
255
+
php artisan make:migration create_products_table
256
+
```
257
+
258
+
Open the generated migration class (`database/migrations/<timestamp>_create_products_table.php`) and add some columns:
259
+
260
+
```patch
261
+
public function up(): void
262
+
{
263
+
Schema::create('products', function (Blueprint $table) {
264
+
$table->id();
265
+
266
+
+ $table->string('name');
267
+
+ $table->decimal('price', 8, 2);
268
+
+ $table->text('description');
269
+
+ $table->boolean('is_active')->default(true);
270
+
+ $table->date('created_date')->nullable();
271
+
272
+
$table->timestamps();
273
+
});
274
+
}
275
+
```
276
+
277
+
Finally, execute the migration:
278
+
279
+
```console
280
+
php artisan
281
+
```
282
+
283
+
And after that, just adding the `#[ApiResource]` attribute as follows onto your model:
284
+
285
+
```patch
286
+
<?php
287
+
288
+
namespace App\Models;
289
+
//app/Models/Product.php
290
+
+use ApiPlatform\Metadata\ApiResource;
291
+
use Illuminate\Database\Eloquent\Model;
292
+
293
+
+#[ApiResource]
294
+
class Product extends Model {}
295
+
```
296
+
297
+
While attributes (introduced in PHP 8) are the preferred way to configure your API Platform resources, it’s also possible to use a trait instead.
298
+
```patch
299
+
<?php
300
+
301
+
namespace App\Models;
302
+
//app/Models/Product.php
303
+
+use ApiPlatform\Metadata\IsApiResource;
304
+
use Illuminate\Database\Eloquent\Model;
305
+
306
+
class Product extends Model
307
+
{
308
+
+ use IsApiResource;
309
+
}
310
+
```
311
+
312
+
See the [Using The IsApiResourceTrait Instead of Attributes documentation](../laravel/index.md#using-the-isapiresourcetrait-instead-of-attributes) for examples of advanced configuration in both cases (attributes or static method).
313
+
314
+
**You're done!** 🎉
315
+
316
+
You now have a fully featured API exposing your entities.
317
+
318
+
Run the Laravel app with the Laravel's local development server using [the Artisan Console component](https://laravel.com/docs/artisan) (`php artisan serve`) and browse the API entrypoint at `http://localhost:8000/api`.
319
+
320
+
Using configurations, API Platform generates metadata that will automatically register the following REST [operations](operations.md)
GET | /products | Retrieve the (paginated) collection
328
+
POST | /products | Create a new product
329
+
GET | /products/{id} | Retrieve a product
330
+
PATCH | /products/{id} | Apply a partial modification to a product
331
+
DELETE | /products/{id} | Delete a product
332
+
333
+
In addition, among other things, API Platform under the hood does the following:
334
+
- Generated machine-readable documentations of the API in the [OpenAPI (formerly known as Swagger)](../core/openapi.md) (available at `http://127.0.0.1:8000/api/docs.json`) and [JSON-LD](https://json-ld.org)/[Hydra](https://www.hydra-cg.com) formats using this metadata
335
+
- Generated nice human-readable documentation and a sandbox for the API with [SwaggerUI](https://swagger.io/tools/swagger-ui/) (Redoc is also available out-of-the-box)
336
+
337
+
## Interactions with the API
338
+
339
+
Interact with the API using a REST client (we recommend [Hoppscotch](https://hoppscotch.io/)) or [API Platform Admin](../admin/index.md).
340
+
341
+
## Examples
342
+
343
+
Take a look at [the API Platform demo](https://github.com/api-platform/demo).
Copy file name to clipboardExpand all lines: core/graphql.md
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -21,7 +21,7 @@ docker compose exec php sh -c '
21
21
22
22
You can now use GraphQL at the endpoint: `https://localhost:8443/graphql`.
23
23
24
-
*Note:* If you used [Symfony Flex to install API Platform](../distribution/index.md#using-symfony-flex-and-composer-advanced-users), URLs will be prefixed with `/api` by default. For example, the GraphQL endpoint will be: `https://localhost:8443/api/graphql`.
24
+
*Note:* If you used [Symfony Flex to install API Platform](../symfony/index.md#using-symfony-flex-and-composer-advanced-users), URLs will be prefixed with `/api` by default. For example, the GraphQL endpoint will be: `https://localhost:8443/api/graphql`.
0 commit comments