This project demonstrates how to use the Stack on Cloud API client generated from the OpenAPI specification.
- Node.js (v14 or higher)
- npm (v6 or higher)
- An API key from Stack on Cloud
- Clone the repository and install dependencies:
npm install- Create a
.envfile from the example:
cp .env.example .env- Add your API key to the
.envfile:
API_KEY=your_api_key_here
The API client is generated using the OpenAPI Generator CLI. The generator configuration is in openapi-config.yaml.
To regenerate the client:
npm run api:generate-clientThis will generate the TypeScript client in src/lib/api/ based on the OpenAPI specification in openapi.spec.json.
The example demonstrates basic CRUD operations using the generated client:
- Creating a profile
- Listing profiles with pagination
- Getting a profile by ID
- Updating a profile
- Deleting a profile
To run the example:
- Build the TypeScript code:
npm run build- Run the example:
npm startsrc/example.ts- Example usage of the API clientsrc/lib/api/- Generated API client codeopenapi.spec.json- OpenAPI specificationopenapi-config.yaml- OpenAPI generator configuration.env- Environment variables (API key)
The generated client provides:
- Type-safe API calls
- Promise-based async methods
- Automatic request/response handling
- Error handling with TypeScript types
- Configuration options (base URL, headers, etc.)
The example includes proper error handling for:
- API errors (4xx, 5xx responses)
- Network errors
- Missing or invalid configuration
- Type validation errors
The ProfileApi class provides the following methods:
createProfile(profile: ApiProfile)listProfile(page?: number, size?: number, sort?: string)getProfileById(id: string)updateProfile(id: string, profile: ApiProfile)deleteProfile(id: string)
Each method returns a Promise that resolves with the API response.