Skip to content

Commit 804b7c7

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

File tree

1 file changed

+137
-0
lines changed

1 file changed

+137
-0
lines changed

core/client-integration.md

Lines changed: 137 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,137 @@
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. It automatically adapts to your
27+
API schema and provides extensive customization options.
28+
29+
[Learn more about API Platform Admin](../admin/index.md).
30+
31+
#### Create Client
32+
33+
The Client Generator creates JavaScript/TypeScript clients based on your API documentation. It generates code that
34+
integrates seamlessly with your API endpoints, reducing development time and errors.
35+
36+
[Learn more about the Create Client](../create-client/index.md)
37+
38+
### JavaScript Libraries
39+
40+
#### @api-platform/ld
41+
42+
The [@api-platform/ld](https://www.npmjs.com/package/@api-platform/ld) JavaScript library simplifies working with Linked Data. It helps parse and serialize data in formats such as JSON-LD,
43+
making it easier to handle complex relationships in your applications.
44+
45+
Example: Loading authors when required with a Linked Data approach:
46+
47+
```json
48+
{
49+
"@id": "/books/1",
50+
"@type": ["https://schema.org/Book"],
51+
"title": "Hyperion",
52+
"author": "https://localhost/authors/1"
53+
}
54+
```
55+
56+
Given an API referencing books and their authors, where `GET /books/1` returns:
57+
58+
```javascript
59+
import ld from '@api-platform/ld'
60+
61+
const pattern = new URLPattern("/authors/:id", "https://localhost");
62+
const books = await ld('/books', {
63+
urlPattern: pattern,
64+
onUpdate: (newBooks) => {
65+
log()
66+
}
67+
})
68+
69+
function log() {
70+
console.log(books.author?.name)
71+
}
72+
73+
log()
74+
```
75+
76+
With [@api-platform/ld](https://www.npmjs.com/package/@api-platform/ld), authors are automatically loaded when needed.
77+
78+
[Read the full documentation](https://edge-side-api.rocks/linked-data).
79+
80+
#### @api-platform/mercure
81+
82+
[Mercure](https://mercure.rocks/spec) is a real-time communication protocol. The [@api-platform/mercure](https://www.npmjs.com/package/@api-platform/mercure)
83+
library enables you to subscribe to updates and deliver real-time data seamlessly.
84+
85+
Example: Subscribing to author updates:
86+
87+
```javascript
88+
import mercure, { close } from "@api-platform/mercure";
89+
90+
const res = await mercure('https://localhost/authors/1', {
91+
onUpdate: (author) => console.log(author)
92+
})
93+
94+
const author = res.then(res => res.json())
95+
96+
// Close if you need to
97+
history.onpushstate = function(e) {
98+
close('https://localhost/authors/1')
99+
}
100+
```
101+
102+
Assuming `/authors/1` returned the following:
103+
104+
```http request
105+
Link: <https://localhost/authors/1>; rel="self"
106+
Link: <https://localhost/.well-known/mercure>; rel="mercure"
107+
```
108+
109+
An `EventSource` subscribes to the topic `https://localhost/authors/1` on the hub `https://localhost/.well-known/mercure`.
110+
111+
[Read the full documentation](https://edge-side-api.rocks/mercure).
112+
113+
#### @api-platform/api-doc-parser
114+
115+
The [@api-platform/api-doc-parser](https://www.npmjs.com/package/@api-platform/api-doc-parser) library parses Hydra API documentation, making it easier to interact with APIs.
116+
It provides metadata handling and generates client code effortlessly.
117+
118+
Key Features:
119+
120+
- Parse Hydra API documentation.
121+
- Generate TypeScript-friendly models.
122+
- Support for filters, pagination, and more.
123+
124+
Example: Parsing [Hydra](http://hydra-cg.com/) API Documentation:
125+
126+
```javascript
127+
import { parseHydraDocumentation } from '@api-platform/api-doc-parser';
128+
129+
parseHydraDocumentation('https://demo.api-platform.com').then(({api}) => console.log(api));
130+
```
131+
This example fetches Hydra documentation from `https://demo.api-platform.com`, parses it, and logs the resulting API
132+
structure. The `parseHydraDocumentation` method is particularly useful for building metadata-driven clients or handling advanced API interactions.
133+
134+
[Read the full documentation](https://github.com/api-platform/api-doc-parser).
135+
136+
137+

0 commit comments

Comments
 (0)