flotiq-codegen-ts
v1.4.0
Published
CLI tool to generate API clients using Flotiq API and OpenAPI Generator
Downloads
360
Maintainers
Readme
flotiq-codegen-ts
This package generates Typescript Fetch API integration for your Flotiq project.
See it in action!
Go to this JSFiddle to see a (limited) demo.
Quickstart
npx flotiq-codegen-ts generate
Usage
Run flotiq-codegen-ts
, provide your API key and wait for your Typescript code to be generated in the flotiqApi
folder.
Then start using it:
import {FlotiqApi} from 'flotiqApi/src';
const FLOTIQ_RO_API_KEY = 'YOUR_API_KEY';
const flotiq = new FlotiqApi(FLOTIQ_RO_API_KEY);
// Use your IDE IntelliSense to work with types & api endpoints!
const eventList = await flotiq.EventAPI.list({limit: 100});
Usage in JS project
If you wish to use flotiqApi
in JS project you can use flotiq-codegen-ts
with --compiled-js
/-c
flag
npx flotiq-codegen-ts generate --compiled-js
Now set of compiled d.ts
and .js
will be automatically generated in your flotiqApi
folder.
You can now import and use the API in your project:
import {FlotiqApi} from 'flotiqApi/index';
const FLOTIQ_RO_API_KEY = 'YOUR_API_KEY';
const flotiq = new FlotiqApi(FLOTIQ_RO_API_KEY);
// Use your IDE IntelliSense to work with types & api endpoints!
const eventList = await flotiq.EventAPI.list({limit: 100});
Watching for changes in your data in Flotiq
The flotiq-codegen-ts
tool offers a feature to continuously monitor changes in the content on your Flotiq account. It
automatically regenerates the SDK whenever changes are detected, ensuring that developers always have the most
up-to-date data models in their IDE without manual intervention.
The --watch
/-w
option for flotiq-codegen-ts
ensures your SDK stays up-to-date by automatically monitoring and regenerating
based on content changes.
If you want to see changes made in Flotiq by your content editor in your IDE, use flotiq-codegen-ts
with --watch
/-w
flag
npx flotiq-codegen-ts generate --watch
or, if you want your SDK to be directly compiled to JavaScript use flotiq-codegen-ts
with flags --watch
/-w
and --compiled-js
/-c
npx flotiq-codegen-ts generate --watch --compiled-js
Now, flotiq-codegen-ts
will check for changes in your Flotiq content every 10 seconds. If changes are detected, it will
automatically regenerate your SDK to reflect the updates.
Surpressing output messages
If you don't want to receive output messages, pass --silent
/-s
option to limit number of logs. This option assumes, that the generator cannot read api key from .env.*
file and will not ask for key in the console.
npx flotiq-codegen-ts generate --silent
This is especially useful when you are using generator with other automation tools or you are running generate function by hand.
Changing SDK output path
By default, the SDK is generated in the flotiqApi
folder in your working directory.
If you want to change the path for the generated SDK, use the --output
/-o
option with your chosen path.
npx flotiq-codegen-ts generate --output ./lib/flotiqApi
In the example above, the SDK will be placed in the flotiqApi
folder within lib
in your working directory.
Node.js api
You can use command handler in your scripts by importing command handler
const {handler} = require('flotiq-codegen-ts/commands/generate');
await handler({flotiqApiKey: 'test-ro-key', watch: false, silent: false, compiledJs: false});
Developing
To start developing this project, follow these steps:
- Clone the repository
git clone [email protected]:flotiq/flotiq-codegen-ts.git
- Install dependencies
yarn install
- Run the project
yarn start
Collaborating
If you wish to talk with us about this project, feel free to hop on our .
If you found a bug, please report it in issues.