Api Platform conference
Register now
v2.4 Typescript Interfaces
API Platform Conference
September 19-20, 2024 | Lille & online

The international conference on the API Platform Framework

API Platform Conference 2024: meet the best PHP, JavaScript and API experts

Learn more about the event, register for the conference, and get ready for two days of inspiration, ideas, and knowledge-sharing with our incredible lineup of renowned specialists and advocates.

Register now

# Typescript Interfaces

The TypeScript Generator allows you to create TypeScript interfaces that you can embed in any TypeScript-enabled project (React, Vue.js, Angular..)

To do so, run the client generator:

$ npx @api-platform/client-generator --generator typescript https://demo.api-platform.com src/ --resource foo
# Replace the URL by the entrypoint of your Hydra-enabled API
# "src/" represents where the interfaces will be generated
# Omit the resource flag to generate files for all resource types exposed by the API

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.

NOTE: If you are not sure what the entrypoint is, see Troubleshooting

# Example

Assuming you have 2 resources in your application, Foo and Bar, when you run

$ npx @api-platform/client-generator --generator typescript https://demo.api-platform.com src/

you will obtain 2 .ts files arranged as following:

  • src/
    • interfaces/
      • foo.ts
      • bar.ts

You can also help us improve the documentation of this page.

Made with love by

Les-Tilleuls.coop can help you design and develop your APIs and web projects, and train your teams in API Platform, Symfony, Next.js, Kubernetes and a wide range of other technologies.

Learn more

Copyright © 2023 Kévin Dunglas

Sponsored by Les-Tilleuls.coop