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
+28-12Lines changed: 28 additions & 12 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -35,6 +35,23 @@ the admin's domain to access it.
35
35
To do so, update the value of the `CORS_ALLOW_ORIGIN` parameter in `api/.env` (it will be set to `^https?://localhost:?[0-9]*$`
36
36
by default).
37
37
38
+
If you're not using the API Platform distribution, you will need to adjust the 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).
39
+
Here is a sample configuration (if you use the API Platform distribution, you can skip this step):
40
+
41
+
```yaml
42
+
# config/packages/nelmio-cors.yaml
43
+
44
+
nelmio_cors:
45
+
paths:
46
+
'^/api/':
47
+
origin_regex: true
48
+
allow_origin: ['^http://localhost:[0-9]+'] # You probably want to change this regex to match your real domain
@@ -50,12 +67,12 @@ The API Platform's admin parses the Hydra documentation exposed by the API and t
50
67
### Using Custom Components
51
68
52
69
In the following example, we change components used for the `description` property of the `books` resource to ones accepting HTML (respectively `RichTextField` that renders HTML markup and `RichTextInput`, a WYSWYG editor).
53
-
(To use the `RichTextInput`, the `aor-rich-text-input` package is must be installed: `yarn add aor-rich-text-input`).
70
+
(To use the `RichTextInput`, the `ra-input-rich-text` package is must be installed: `yarn add ra-input-rich-text`).
54
71
55
72
```javascript
56
73
import React from 'react';
57
-
import { RichTextField } from'admin-on-rest';
58
-
importRichTextInputfrom'aor-rich-text-input';
74
+
import { RichTextField } from 'react-admin';
75
+
import RichTextInput from 'ra-input-rich-text';
59
76
import { HydraAdmin } from '@api-platform/admin';
60
77
import parseHydraDocumentation from '@api-platform/api-doc-parser/lib/hydra/parseHydraDocumentation';
The `field` property of the `Field` class allows to set the component used to render a property in list and show screens.
86
103
The `input` property allows to set the component to use to render the input used in create and edit screens.
87
104
88
-
Any [field](https://marmelab.com/admin-on-rest/Fields.html) or [input](https://marmelab.com/admin-on-rest/Inputs.html) provided by the Admin On Rest library can be used.
105
+
Any [field](https://marmelab.com/react-admin/Fields.html) or [input](https://marmelab.com/react-admin/Inputs.html) provided by the React Admin library can be used.
89
106
90
-
To go further, take a look to the "[Including admin-on-rest on another React app](https://marmelab.com/admin-on-rest/CustomApp.html)" documentation page of Admin On Rest to learn how to use directly redux, react-router, and redux-saga along with components provided by this library.
107
+
To go further, take a look to the "[Including react-admin on another React app](https://marmelab.com/react-admin/CustomApp.html)" documentation page of React Admin to learn how to use directly redux, react-router, and redux-saga along with components provided by this library.
91
108
92
109
### Managing Files and Images
93
110
94
111
In the following example, we will:
95
-
* find every [ImageObject](http://schema.org/ImageObject) resources. For each [contentUrl](http://schema.org/contentUrl) fields, we will use [ImageField](https://marmelab.com/admin-on-rest/Fields.html#imagefield) as `field` and [ImageInput](https://marmelab.com/admin-on-rest/Inputs.html#imageinput) as `input`.
96
-
*[ImageInput](https://marmelab.com/admin-on-rest/Inputs.html#imageinput) will return a [File](https://developer.mozilla.org/en/docs/Web/API/File) instance. In this example, we will send a multi-part form data to a special action (`https://demo.api-platform.com/images/upload`). The action will return the ID of the uploaded image. We will "replace" the [File](https://developer.mozilla.org/en/docs/Web/API/File) instance by the ID in `normalizeData`.
97
-
* As `contentUrl` fields will return a string, we have to convert Hydra data to AOR data. This action will be done by `denormalizeData`.
112
+
* find every [ImageObject](http://schema.org/ImageObject) resources. For each [contentUrl](http://schema.org/contentUrl) fields, we will use [ImageField](https://marmelab.com/react-admin/Fields.html#imagefield) as `field` and [ImageInput](https://marmelab.com/react-admin/Inputs.html#imageinput) as `input`.
113
+
* [ImageInput](https://marmelab.com/react-admin/Inputs.html#imageinput) will return a [File](https://developer.mozilla.org/en/docs/Web/API/File) instance. In this example, we will send a multi-part form data to a special action (`https://demo.api-platform.com/images/upload`). The action will return the ID of the uploaded image. We will "replace" the [File](https://developer.mozilla.org/en/docs/Web/API/File) instance by the ID in `normalizeData`.
114
+
* As `contentUrl` fields will return a string, we have to convert Hydra data to React Admin data. This action will be done by `denormalizeData`.
Copy file name to clipboardExpand all lines: core/content-negotiation.md
+15-7Lines changed: 15 additions & 7 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -5,7 +5,7 @@ It leverages the [`willdurand/negotiation`](https://github.com/willdurand/Negoti
5
5
6
6
By default, only the [JSON-LD](https://json-ld.org) format is enabled. However API Platform Core supports many more formats and can be extended.
7
7
8
-
The framework natively supports JSON-LD, HAL, raw JSON, XML, YAML and CSV (YAML and CSV support is only available if you use Symfony 3.2+).
8
+
The framework natively supports JSON-LD, GraphQL, JSONAPI, HAL, raw JSON, XML, YAML and CSV (YAML and CSV support is only available if you use Symfony 3.2+).
9
9
10
10
Both XML and JSON formats are experimental and there are no assurance that we will not break them.
11
11
@@ -19,16 +19,19 @@ Available formats are:
19
19
Format | Format name | MIME types | Backward Compatibility guaranteed
[JSON](https://www.json.org/) | `json` | `application/json` | no
26
+
[XML](https://www.w3.org/XML/) | `xml` | `application/xml`, `text/xml` | no
27
+
[YAML](http://yaml.org/) | `yaml` | `application/x-yaml` | no
28
+
[CSV](https://tools.ietf.org/html/rfc4180) | `csv` | `text/csv` | no
29
+
[HTML](https://whatwg.org/) (API docs) | `html` | `text/html` | no
26
30
27
-
If the client requested format is not specified (if it's not supported, it will throw an HTTP bad format error), the response format will be the first format defined in the `formats` configuration key (see below).
31
+
If the client requested format is not specified (if it's not supported, it will throw an HTTP bad request error), the response format will be the first format defined in the `formats` configuration key (see below).
28
32
An example using the built-in XML support is available in [Behat specs](https://github.com/api-platform/core/blob/master/features/main/content_negotiation.feature).
29
33
30
-
The API Platform content negotiation system is extendable. Support for other formats (such as [JSONAPI](http://jsonapi.org/))
31
-
can be added by [creating and registering appropriate encoders and, sometimes, normalizers](https://symfony.com/doc/current/serializer.html#adding-normalizers-and-encoders). Adding support for other
34
+
The API Platform content negotiation system is extendable. Support for other formats can be added by [creating and registering appropriate encoders and, sometimes, normalizers](https://symfony.com/doc/current/serializer.html#adding-normalizers-and-encoders). Adding support for other
32
35
standard hypermedia formats upstream is welcome. Don't hesitate to contribute by adding your encoders and normalizers
33
36
to API Platform Core.
34
37
@@ -45,12 +48,17 @@ api_platform:
45
48
formats:
46
49
jsonld: ['application/ld+json']
47
50
jsonhal: ['application/hal+json']
51
+
jsonapi: ['application/vnd.api+json']
48
52
json: ['application/json']
49
53
xml: ['application/xml', 'text/xml']
54
+
yaml: ['application/x-yaml']
55
+
csv: ['text/csv']
50
56
html: ['text/html']
51
57
myformat: ['application/vnd.myformat']
52
58
```
53
59
60
+
To enable GraphQL support, [read the dedicated chapter](graphql.md).
61
+
54
62
Because the Symfony Serializer component is able to serialize objects in XML, sending an `Accept` HTTP header with the
55
63
`text/xml`string as value is enough to retrieve XML documents from our API. However API Platform knows nothing about the
56
64
`myformat`format. We need to register an encoder and optionally a normalizer for this format.
Copy file name to clipboardExpand all lines: core/events.md
+3-1Lines changed: 3 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -80,7 +80,7 @@ Name | Event | Pre & Post hooks
80
80
`DeserializeListener` | `kernel.request` | `PRE_DESERIALIZE`, `POST_DESERIALIZE`| 2 | deserialize data into a PHP entity (`GET`, `POST`, `DELETE`); update the entity retrieved using the data provider (`PUT`)
`WriteListener` | `kernel.view` | `PRE_WRITE`, `POST_WRITE` | 32 | if using the Doctrine ORM, persist data (`POST`, `PUT`, `DELETE`)
83
-
`SerializeListener` | `kernel.view` | None | 16 | serialize the PHP entity in string [according to the request format](content-negotiation.md)
83
+
`SerializeListener` | `kernel.view` | `PRE_SERIALIZE`, `POST_SERIALIZE` | 16 | serialize the PHP entity in string [according to the request format](content-negotiation.md)
84
84
`RespondListener` | `kernel.view` | `PRE_RESPOND`, `POST_RESPOND` | 8 | transform serialized to a `Symfony\Component\HttpFoundation\Response` instance
85
85
`AddLinkHeaderListener` | `kernel.response` | None | 0 | add a `Link` HTTP header pointing to the Hydra documentation
86
86
`ValidationExceptionListener` | `kernel.exception` | None | 0 | serialize validation exceptions in the Hydra format
0 commit comments