Skip to content

Commit 3962b58

Browse files
committed
Merge 4.0
2 parents 39adc7b + 46491a6 commit 3962b58

File tree

13 files changed

+170
-23
lines changed

13 files changed

+170
-23
lines changed

core/bootstrap.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Bootstraping the core library
1+
# Bootstrapping the Core Library
22

33
You may want to run a minimal version of API Platform. This one file runs API Platform (without GraphQL, Eloquent, Doctrine MongoDB...).
44
It requires the following Composer packages:

core/client-integration.md

Lines changed: 143 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,143 @@
1+
# Client Integrations
2+
3+
## Edge Side API (ESA)
4+
5+
> [Edge Side APIs (ESA)](https://edge-side-api.rocks/) is an architectural pattern that allows the creation of more
6+
> reliable, efficient, and less resource-intensive APIs. It revives the core REST/HATEOAS principles while taking full
7+
> advantage of the new capabilities provided by the web platform.
8+
>
9+
> ESA promotes a mixed approach (synchronous and asynchronous), offering simplicity in development and use, exceptional
10+
> performance, and the ability for clients to receive real-time updates of the resources they fetched. ESA also leverages
11+
> existing standards to expose API documentation, enabling the creation of generic clients capable of discovering the
12+
> API’s capabilities at runtime.
13+
>
14+
> *From [ESA White Paper](https://edge-side-api.rocks/white-paper)*
15+
16+
## JavaScript Client Integrations
17+
18+
API Platform offers a suite of tools and libraries that streamline the integration of JavaScript clients with APIs.
19+
These tools simplify development by automating tasks such as data fetching, administration panel creation,
20+
and real-time updates. Below is a detailed overview of the available clients, libraries, and their usage.
21+
22+
### Clients and Tools Overview
23+
24+
#### Admin
25+
26+
API Platform Admin is a dynamic administration panel generator built with [React-Admin](https://marmelab.com/react-admin/).
27+
It automatically adapts to your API schema and provides extensive customization options. It can read an [OpenAPI](https://www.openapis.org/)
28+
specification or a [Hydra](https://www.hydra-cg.com/) specification. API Platform supports both [OpenAPI](openapi.md) and
29+
[Hydra](extending-jsonld-context.md#hydra) from scratch!
30+
31+
[Learn more about API Platform Admin](../admin/index.md).
32+
33+
#### Create Client
34+
35+
The Client Generator creates JavaScript/TypeScript clients based on your API documentation. It generates code that
36+
integrates seamlessly with your API endpoints, reducing development time and errors.
37+
38+
[Learn more about the Create Client](../create-client/index.md)
39+
40+
### JavaScript Libraries
41+
42+
#### api-platform/ld
43+
44+
The [api-platform/ld](https://edge-side-api.rocks/linked-data) JavaScript library simplifies working with Linked Data.
45+
It helps parse and serialize data in formats such as [JSON-LD](extending-jsonld-context.md#json-ld), making it easier to
46+
handle complex relationships in your applications.
47+
48+
For example, let's load authors when required with a Linked Data approach.
49+
Given an API referencing books and their authors, where `GET /books/1` returns:
50+
51+
```json
52+
{
53+
"@id": "/books/1",
54+
"@type": ["https://schema.org/Book"],
55+
"title": "Hyperion",
56+
"author": "https://localhost/authors/1"
57+
}
58+
```
59+
60+
Use an [URLPattern](https://urlpattern.spec.whatwg.org/) to load authors automatically when fetching an author property
61+
such as `books.author?.name`:
62+
63+
```javascript
64+
import ld from '@api-platform/ld'
65+
66+
const pattern = new URLPattern("/authors/:id", "https://localhost");
67+
const books = await ld('/books', {
68+
urlPattern: pattern,
69+
onUpdate: (newBooks) => {
70+
log()
71+
}
72+
})
73+
74+
function log() {
75+
console.log(books.author?.name)
76+
}
77+
78+
log()
79+
```
80+
81+
With [api-platform/ld](https://edge-side-api.rocks/linked-data), authors are automatically loaded when needed.
82+
83+
[Read the full documentation](https://edge-side-api.rocks/linked-data).
84+
85+
#### api-platform/mercure
86+
87+
[Mercure](https://mercure.rocks/spec) is a real-time communication protocol. The [api-platform/mercure](https://edge-side-api.rocks/mercure)
88+
library enables you to subscribe to updates and deliver real-time data seamlessly.
89+
90+
Our frontend library allows you to subscribe to updates with efficiency, re-using the hub connection and adding topics
91+
automatically as they get requested. API Platform [supports Mercure](mercure.md) and automatically sets the
92+
[Link header](https://mercure.rocks/spec#content-negotiation) making auto-discovery a breeze. For example:
93+
94+
```javascript
95+
import mercure, { close } from "@api-platform/mercure";
96+
97+
const res = await mercure('https://localhost/authors/1', {
98+
onUpdate: (author) => console.log(author)
99+
})
100+
101+
const author = res.then(res => res.json())
102+
103+
// Close if you need to
104+
history.onpushstate = function(e) {
105+
close('https://localhost/authors/1')
106+
}
107+
```
108+
109+
Assuming `/authors/1` returned the following:
110+
111+
```http
112+
Link: <https://localhost/authors/1>; rel="self"
113+
Link: <https://localhost/.well-known/mercure>; rel="mercure"
114+
```
115+
116+
An `EventSource` subscribes to the topic `https://localhost/authors/1` on the hub `https://localhost/.well-known/mercure`.
117+
118+
[Read the full documentation](https://edge-side-api.rocks/mercure).
119+
120+
#### api-platform/api-doc-parser
121+
122+
The [api-platform/api-doc-parser](https://github.com/api-platform/api-doc-parser) that parses Hydra, Swagger,
123+
OpenAPI, and GraphQL documentation into an intermediate format for generating API clients and scaffolding code.
124+
It integrates well with API Platform and supports auto-detecting resource relationships.
125+
126+
Key Features:
127+
128+
- Multi-format support: Parses Hydra, Swagger (OpenAPI v2), OpenAPI v3, and GraphQL.
129+
- Intermediate representation: Converts API docs into a usable format for generating clients, scaffolding code, or building admin interfaces.
130+
- API Platform integration: Works seamlessly with API Platform.
131+
- Auto-detection of resource relationships: Automatically detects relationships between resources based on documentation.
132+
133+
Example: Parsing [Hydra](http://hydra-cg.com/) API Documentation:
134+
135+
```javascript
136+
import { parseHydraDocumentation } from '@api-platform/api-doc-parser';
137+
138+
parseHydraDocumentation('https://demo.api-platform.com').then(({api}) => console.log(api));
139+
```
140+
This example fetches Hydra documentation from `https://demo.api-platform.com`, parses it, and logs the resulting API
141+
structure. The `parseHydraDocumentation` method is particularly useful for building metadata-driven clients or handling advanced API interactions.
142+
143+
[Read the full documentation](https://github.com/api-platform/api-doc-parser).

core/content-negotiation.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ Available formats are:
2424
| [GraphQL](graphql.md) | n/a | n/a | yes |
2525
| [JSON:API](https://jsonapi.org/) | `jsonapi` | `application/vnd.api+json` | yes |
2626
| [HAL](https://stateless.group/hal_specification.html) | `jsonhal` | `application/hal+json` | yes |
27-
| [YAML](https://yaml.org/) | `yaml` | `application/x-yaml` | no |
27+
| [YAML](https://yaml.org/) | `yaml` | `application/yaml` | no |
2828
| [CSV](https://tools.ietf.org/html/rfc4180) | `csv` | `text/csv` | no |
2929
| [HTML](https://whatwg.org/) (API docs) | `html` | `text/html` | no |
3030
| [XML](https://www.w3.org/XML/) | `xml` | `application/xml`, `text/xml` | no |

core/openapi.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -637,7 +637,7 @@ Manually register the Swagger UI controller:
637637
# app/config/routes.yaml
638638
api_doc:
639639
path: /api_documentation
640-
controller: api_platform.swagger_ui.processor
640+
controller: api_platform.action.documentation
641641
```
642642
643643
Change `/api_documentation` to the URI you wish Swagger UI to be accessible on.
@@ -649,9 +649,9 @@ Manually register the Swagger UI controller:
649649
```php
650650
// routes/web.php
651651
use Illuminate\Support\Facades\Route;
652-
use ApiPlatform\Laravel\State\SwaggerUiProcessor;
652+
use ApiPlatform\Laravel\Controller\DocumentationController;
653653
654-
Route::post('/api_documentation', SwaggerUiProcessor::class)
654+
Route::post('/api_documentation', DocumentationController::class)
655655
->name('api_doc');
656656
```
657657

core/performance.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ The integration using the cache handler is quite simple. You just have to update
4545
+ --with github.com/dunglas/mercure/caddy \
4646
+ --with github.com/dunglas/vulcain/caddy \
4747
+ --with github.com/dunglas/caddy-cbrotli \
48-
+ --with github.com/caddyserver/cache-handler
4948
+ # You should use another storage than the default one (e.g. otter).
5049
+ # The list of the available storages can be find either on the documentation website (https://docs.souin.io/docs/storages/) or on the storages repository https://github.com/darkweak/storages
5150
+ --with github.com/caddyserver/cache-handler

create-client/typescript.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# TypeScript Interfaces
22

3-
The TypeScript Generator allows you to create [TypeScript interfaces](https://www.typescriptlang.org/docs/handbook/interfaces.html)
3+
The TypeScript Generator allows you to create [TypeScript interfaces](https://www.typescriptlang.org/docs/handbook/2/everyday-types.html#interfaces)
44
that you can embed in any TypeScript-enabled project (React, Vue.js, Angular..).
55

66
To do so, run the generator:

extra/contribution-guides.md

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
1-
# Contribution guides
1+
# Contribution Guides
22

3-
1. [API Platform Core Library](https://github.com/api-platform/core/blob/main/CONTRIBUTING.md)
4-
2. [API Platform Schema Generator](https://github.com/api-platform/schema-generator/blob/main/CONTRIBUTING.md)
5-
3. [API Platform Admin](https://github.com/api-platform/admin/blob/master/CONTRIBUTING.md)
6-
4. [API Platform CRUD Generator](https://github.com/api-platform/create-client/blob/master/CONTRIBUTING.md)
3+
## API Platform Core
4+
- [General Contribution Guide](https://github.com/api-platform/core/blob/main/CONTRIBUTING.md)
5+
- [Laravel-Specific Contribution Guide](https://github.com/api-platform/core/blob/main/src/Laravel/CONTRIBUTING.md)
76

8-
**To report a security issue, please refer to [the dedicated document](security.md).**
7+
## API Platform Tools
8+
- [Schema Generator Contribution Guide](https://github.com/api-platform/schema-generator/blob/main/CONTRIBUTING.md)
9+
- [Admin Contribution Guide](https://github.com/api-platform/admin/blob/master/CONTRIBUTING.md)
10+
- [CRUD Generator Contribution Guide](https://github.com/api-platform/create-client/blob/master/CONTRIBUTING.md)
11+
12+
**To report a security issue, please take a look at [the dedicated document](security.md).**
913

1014
<p align="center" class="symfonycasts"><a href="https://symfonycasts.com/screencast/contributing?cid=apip"><img src="../symfony/images/symfonycasts-player.png" alt="JWT screencast"><br>Watch the Contributing back to Symfony screencast (free)</a></p>

laravel/index.md

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -193,8 +193,7 @@ use ApiPlatform\Metadata\Get;
193193
#[Get(uriTemplate: '/my_custom_book/{id}')]
194194
class Book
195195
{
196-
public string $id;
197-
public string $title;
196+
public function __construct(public string $id, public string $title) {}
198197
}
199198
```
200199

@@ -224,6 +223,7 @@ namespace App\State;
224223
use ApiPlatform\Metadata\Operation;
225224
use ApiPlatform\State\ProviderInterface;
226225
use App\Models\Book as BookModel;
226+
use App\ApiResource\Book;
227227

228228
final class BookProvider implements ProviderInterface
229229
{
@@ -242,8 +242,8 @@ Register the state provider:
242242

243243
namespace App\Providers;
244244

245-
use ApiPlatform\State\ProviderInterface;
246245
use App\State\BookProvider;
246+
use ApiPlatform\State\ProviderInterface;
247247
use Illuminate\Contracts\Foundation\Application;
248248
use Illuminate\Support\ServiceProvider;
249249

@@ -273,8 +273,7 @@ use App\State\BookProvider;
273273
#[Get(uriTemplate: '/my_custom_book/{id}', provider: BookProvider::class)]
274274
class Book
275275
{
276-
public string $id;
277-
public string $title;
276+
public function __construct(public string $id, public string $title) {}
278277
}
279278
```
280279

@@ -626,6 +625,7 @@ API Platform provides an easy shortcut to some [useful filters](./filters.md), f
626625
namespace App\Models;
627626

628627
use ApiPlatform\Metadata\ApiResource;
628+
+use ApiPlatform\Metadata\QueryParameter;
629629
+use ApiPlatform\Laravel\Eloquent\Filter\PartialSearchFilter;
630630
use Illuminate\Database\Eloquent\Model;
631631

@@ -645,6 +645,7 @@ It's also possible to enable filters on every exposed property:
645645
namespace App\Models;
646646

647647
use ApiPlatform\Metadata\ApiResource;
648+
+use ApiPlatform\Metadata\QueryParameter;
648649
+use ApiPlatform\Laravel\Eloquent\Filter\PartialSearchFilter;
649650
+use ApiPlatform\Laravel\Eloquent\Filter\OrderFilter;
650651
use Illuminate\Database\Eloquent\Model;

outline.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ chapters:
7070
- form-data
7171
- bootstrap
7272
- configuration
73+
- client-integration
7374
- title: Schema Generator
7475
path: schema-generator
7576
items:

symfony/caddy.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Configuring the Caddy Web Server
1+
# Configuring the Caddy Web Server with Symfony
22

33
[The API Platform distribution](index.md) is shipped with [the Caddy web server](https://caddyserver.com).
44
The build contains the [Mercure](../core/mercure.md) and the [Vulcain](https://vulcain.rocks) Caddy modules.

0 commit comments

Comments
 (0)