Skip to content

Commit 056c448

Browse files
luca-nardellidunglas
authored andcommitted
Add page for typescript client generator (#764)
* Add page for typescript client generator * Update client-generator/typescript.md Co-Authored-By: luca-nardelli <[email protected]> * Update client-generator/typescript.md Co-Authored-By: luca-nardelli <[email protected]> * Remove installation instructions in favor of npx * Use code blocks instead of indentations in markdown * Update client-generator/typescript.md Co-Authored-By: luca-nardelli <[email protected]>
1 parent 068554c commit 056c448

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

client-generator/typescript.md

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# Typescript Interfaces
2+
3+
The TypeScript Generator allows you to create [TypeScript interfaces](https://www.typescriptlang.org/docs/handbook/interfaces.html) that you can embed in any TypeScript-enabled project (React, Vue.js, Angular..)
4+
5+
To do so, run the client generator:
6+
7+
```bash
8+
$ npx @api-platform/client-generator -g typescript https://demo.api-platform.com src/ --resource foo
9+
# Replace the URL by the entrypoint of your Hydra-enabled API
10+
# "src/" represents where the interfaces will be generated
11+
# Omit the resource flag to generate files for all resource types exposed by the API
12+
```
13+
14+
This command parses the Hydra documentation and creates one `.ts` file for each API Resource you have defined in your application, in the `interfaces` subfolder.
15+
16+
NOTE: If you are not sure what the entrypoint is, see [Troubleshooting](troubleshooting.md)
17+
18+
## Example
19+
20+
Assuming you have 2 resources in your application, `Foo` and `Bar`, when you run
21+
22+
```bash
23+
npx @api-platform/client-generator -g typescript https://demo.api-platform.com src/
24+
```
25+
26+
you will obtain 2 `.ts` files arranged as following:
27+
28+
* src/
29+
* interfaces/
30+
* foo.ts
31+
* bar.ts

0 commit comments

Comments
 (0)