Skip to content

Commit c69f8d7

Browse files
committed
docs(client-integration): introduce documentation
1 parent 2fd0a82 commit c69f8d7

File tree

1 file changed

+148
-0
lines changed

1 file changed

+148
-0
lines changed

core/client-integration.md

Lines changed: 148 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,148 @@
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+
Given an API referencing books and their authors, where `GET /books/1` returns:
61+
62+
Use an [URLPattern](https://urlpattern.spec.whatwg.org/) to load authors automatically when fetching an author property
63+
such as `books.author?.name`:
64+
65+
```javascript
66+
import ld from '@api-platform/ld'
67+
68+
const pattern = new URLPattern("/authors/:id", "https://localhost");
69+
const books = await ld('/books', {
70+
urlPattern: pattern,
71+
onUpdate: (newBooks) => {
72+
log()
73+
}
74+
})
75+
76+
function log() {
77+
console.log(books.author?.name)
78+
}
79+
80+
log()
81+
```
82+
83+
With [api-platform/ld](https://edge-side-api.rocks/linked-data), authors are automatically loaded when needed.
84+
85+
[Read the full documentation](https://edge-side-api.rocks/linked-data).
86+
87+
#### api-platform/mercure
88+
89+
[Mercure](https://mercure.rocks/spec) is a real-time communication protocol. The [api-platform/mercure](https://edge-side-api.rocks/mercure)
90+
library enables you to subscribe to updates and deliver real-time data seamlessly.
91+
92+
Our front-end library allows you to subscribe to updates with efficiency, re-using the hub connection and adding topics
93+
automatically as they get requested. API Platform [supports Mercure](mercure.md) and automatically sets the
94+
[Link header](https://mercure.rocks/spec#content-negotiation) making auto-discovery a breeze. For example:
95+
96+
```javascript
97+
import mercure, { close } from "@api-platform/mercure";
98+
99+
const res = await mercure('https://localhost/authors/1', {
100+
onUpdate: (author) => console.log(author)
101+
})
102+
103+
const author = res.then(res => res.json())
104+
105+
// Close if you need to
106+
history.onpushstate = function(e) {
107+
close('https://localhost/authors/1')
108+
}
109+
```
110+
111+
Assuming `/authors/1` returned the following:
112+
113+
```http request
114+
Link: <https://localhost/authors/1>; rel="self"
115+
Link: <https://localhost/.well-known/mercure>; rel="mercure"
116+
```
117+
118+
An `EventSource` subscribes to the topic `https://localhost/authors/1` on the hub `https://localhost/.well-known/mercure`.
119+
120+
[Read the full documentation](https://edge-side-api.rocks/mercure).
121+
122+
#### api-platform/api-doc-parser
123+
124+
The [api-platform/api-doc-parser](https://github.com/api-platform/api-doc-parser) that parses Hydra, Swagger,
125+
OpenAPI, and GraphQL documentation into an intermediate format for generating API clients and scaffolding code.
126+
It integrates well with API Platform and supports auto-detecting resource relationships.
127+
128+
Key Features:
129+
130+
- Multi-format support: Parses Hydra, Swagger (OpenAPI v2), OpenAPI v3, and GraphQL.
131+
- Intermediate representation: Converts API docs into a usable format for generating clients, scaffolding code, or building admin interfaces.
132+
- API Platform integration: Works seamlessly with API Platform.
133+
- Auto-detection of resource relationships: Automatically detects relationships between resources based on documentation.
134+
135+
Example: Parsing [Hydra](http://hydra-cg.com/) API Documentation:
136+
137+
```javascript
138+
import { parseHydraDocumentation } from '@api-platform/api-doc-parser';
139+
140+
parseHydraDocumentation('https://demo.api-platform.com').then(({api}) => console.log(api));
141+
```
142+
This example fetches Hydra documentation from `https://demo.api-platform.com`, parses it, and logs the resulting API
143+
structure. The `parseHydraDocumentation` method is particularly useful for building metadata-driven clients or handling advanced API interactions.
144+
145+
[Read the full documentation](https://github.com/api-platform/api-doc-parser).
146+
147+
148+

0 commit comments

Comments
 (0)