|
1 | 1 | #API200 SDK Generator |
2 | 2 |
|
3 | | -[](https://badge.fury.io/js/api200-sdk-generator) |
4 | | -[](https://opensource.org/licenses/MIT) |
| 3 | +A TypeScript SDK generator that automatically creates a fully-typed client library for your API200 services. Generate type-safe API clients with zero configuration and full IDE support. |
5 | 4 |
|
6 | | -A powerful CLI tool that automatically generates a TypeScript SDK for your[API 200](https://api200.co) services. Transform your API endpoints into a fully-typed, easy-to-use SDK with a single command. |
| 5 | +##Features |
7 | 6 |
|
8 | | -##🚀 Features |
| 7 | +-**Automatic Type Generation**: Creates TypeScript interfaces from your API schemas |
| 8 | +-**Full Type Safety**: Compile-time error checking for API calls |
| 9 | +-**Zero Configuration**: Works out of the box with sensible defaults |
| 10 | +-**Path & Query Parameters**: Handles both path variables and query strings |
| 11 | +-**Request Body Support**: Type-safe request body handling for POST/PUT/PATCH |
| 12 | +-**Error Handling**: Structured error responses with status codes |
| 13 | +-**IDE Support**: Full IntelliSense and autocomplete support |
9 | 14 |
|
10 | | --**🔧 Zero Configuration** - Just provide your API token and go |
11 | | --**📝 Full TypeScript Support** - Complete type safety with IntelliSense |
12 | | --**🎯 Intuitive API** - Clean, predictable method naming |
13 | | --**⚡ Fast Generation** - Generates SDK in seconds |
14 | | --**🔄 Automatic Updates** - Re-run to sync with API changes |
15 | | --**📦 No Dependencies** - Generated code has zero runtime dependencies |
| 15 | +##Prerequisites |
16 | 16 |
|
17 | | -##📥 Installation |
| 17 | +1.**Register with API200**: Sign up at[API200](https://api200.co) and set up your API proxy platform |
| 18 | +2.**Import/Create Services**: Add your API services to the API200 platform |
| 19 | +3.**Get API Token**: Obtain your user token from the API200 dashboard |
18 | 20 |
|
19 | | -###Global Installation |
20 | | -```bash |
21 | | -npm install -g api200-sdk-generator |
22 | | -``` |
| 21 | +##Installation |
| 22 | + |
| 23 | +Generate your SDK using npx (no installation required): |
23 | 24 |
|
24 | | -###One-time Usage (Recommended) |
25 | 25 | ```bash |
26 | | -npx api200-generate-sdk -tyour_api_token |
| 26 | +npx api200-generate-sdk -tYOUR_API_TOKEN |
27 | 27 | ``` |
28 | 28 |
|
29 | | -##🛠️ Usage |
| 29 | +##Command Options |
30 | 30 |
|
31 | | -###Basic Usage |
32 | | -```bash |
33 | | -npx api200-generate-sdk --token YOUR_API_TOKEN |
34 | | -``` |
| 31 | +| Option| Short| Description| Default| |
| 32 | +|--------|-------|-------------|---------| |
| 33 | +|`--token`|`-t`|**Required.** Your API200 user token|| |
| 34 | +|`--base-url`|`-u`| Base API URL|`https://eu.api200.co/api`| |
| 35 | +|`--output`|`-o`| Output directory|`./src/lib/api200` or`./lib/api200`| |
35 | 36 |
|
36 | | -###Custom Output Directory |
37 | | -```bash |
38 | | -npx api200-generate-sdk -t YOUR_API_TOKEN -o ./src/api |
39 | | -``` |
| 37 | +###Examples |
40 | 38 |
|
41 | | -###Custom Base URL |
42 | 39 | ```bash |
43 | | -npx api200-generate-sdk -t YOUR_API_TOKEN -u https://custom.api200.co/api |
44 | | -``` |
| 40 | +# Basic usage |
| 41 | +npx api200-generate-sdk -t your_token_here |
45 | 42 |
|
46 | | -###All Options |
47 | | -```bash |
48 | | -api200-generate-sdk [options] |
| 43 | +# Custom output directory |
| 44 | +npx api200-generate-sdk -t your_token_here -o ./src/api |
49 | 45 |
|
50 | | -Options: |
51 | | - -t, --token<token> API200 user token (required) |
52 | | - -u, --base-url<url> Base API URL (default:"https://eu.api200.co/api") |
53 | | - -o, --output<path> Output directory (default:"./lib/api200") |
54 | | - -h, --help Displayhelpforcommand |
| 46 | +# Different API region |
| 47 | +npx api200-generate-sdk -t your_token_here -u https://us.api200.co/api |
55 | 48 | ``` |
56 | 49 |
|
57 | | -##📁Generated Structure |
| 50 | +##Generated Structure |
58 | 51 |
|
59 | | -The generator createsa clean, organized SDK structure: |
| 52 | +TheSDKgenerator createsthe following file structure: |
60 | 53 |
|
61 | 54 | ``` |
62 | 55 | lib/api200/ |
63 | | -├── index.ts # Main SDK export |
64 | | -├── types.ts # TypeScript interfaces |
65 | | -├── users.ts # Users service methods |
66 | | -├── orders.ts # Orders service methods |
67 | | -└── payments.ts # Payments service methods |
| 56 | +├── index.ts # Main export file with configured client |
| 57 | +├── api200.ts # Core client and request handling |
| 58 | +├── types.ts # TypeScript type definitions |
| 59 | +└── [service-name].ts # Individual service files |
68 | 60 | ``` |
69 | 61 |
|
70 | | -##💻 Usage Examples |
| 62 | +##Usage Example |
| 63 | + |
| 64 | +###Usage |
71 | 65 |
|
72 | | -###Basic Import and Usage |
73 | 66 | ```typescript |
74 | | -import{api200 }from'./lib/api200'; |
| 67 | +importapi200from'./lib/api200'; |
75 | 68 |
|
76 | 69 | // GET request with path parameter |
77 | | -const user=awaitapi200.users.getUserById.get({ id:"123" }); |
78 | | -console.log(user.data); |
79 | | - |
80 | | -// GET request with query parameters |
81 | | -const users=awaitapi200.users.getUsers.get({ |
82 | | - page:1, |
83 | | - limit:10, |
84 | | - status:"active" |
| 70 | +const { data, error }=awaitapi200.users.getUserById.get({ |
| 71 | + id:"123" |
85 | 72 | }); |
86 | 73 |
|
87 | | -// POST request with body |
88 | | -const newUser=awaitapi200.users.createUser.post({ |
89 | | - requestBody: { |
90 | | - name:"John Doe", |
91 | | - email:"john@example.com" |
92 | | - } |
93 | | -}); |
94 | | -``` |
95 | | - |
96 | | -###Error Handling |
97 | | -```typescript |
98 | | -import {api200 }from'./lib/api200'; |
99 | | -importtype {ApiError }from'./lib/api200/types'; |
100 | | - |
101 | | -try { |
102 | | -const result=awaitapi200.users.getUserById.get({ id:"123" }); |
103 | | -console.log('Success:',result.data); |
104 | | -}catch (error) { |
105 | | -const apiError=errorasApiError; |
106 | | -console.error('Error:',apiError.message); |
107 | | -console.error('Status:',apiError.status); |
| 74 | +if (error) { |
| 75 | +console.error('API Error:',error.message); |
| 76 | +}else { |
| 77 | +console.log('User data:',data); |
108 | 78 | } |
109 | 79 | ``` |
110 | 80 |
|
111 | | -###Type Safety |
112 | | -```typescript |
113 | | -import {api200 }from'./lib/api200'; |
114 | | -importtype {GetUsersByIdParams,PostUsersParams }from'./lib/api200/types'; |
115 | | - |
116 | | -// Fully typed parameters |
117 | | -const params:GetUsersByIdParams= { id:"123" }; |
118 | | -const user=awaitapi200.users.getUserById.get(params); |
119 | | - |
120 | | -// TypeScript will catch type errors |
121 | | -const createParams:PostUsersParams= { |
122 | | - requestBody: { |
123 | | - name:"John", |
124 | | - email:"john@example.com", |
125 | | -// age: "30" // ❌ TypeScript error if age should be number |
126 | | - age:30// ✅ Correct type |
127 | | - } |
128 | | -}; |
129 | | -``` |
| 81 | +###Method Naming Convention |
130 | 82 |
|
131 | | -##🔄 Updating Your SDK |
| 83 | +Methods are generated using the pattern:`[httpMethod][EndpointPath]` |
132 | 84 |
|
133 | | -When your API changes, simply re-run the generator to update your SDK: |
| 85 | +Examples: |
| 86 | +-`GET /users/{id}` →`getUserById.get()` |
| 87 | +-`POST /users` →`createUser.post()` |
| 88 | +-`PUT /users/{id}` →`updateUserById.put()` |
| 89 | +-`DELETE /orders/{orderId}` →`deleteOrderByOrderId.delete()` |
134 | 90 |
|
135 | | -```bash |
136 | | -npx api200-generate-sdk -t YOUR_API_TOKEN |
137 | | -``` |
138 | | - |
139 | | -This will overwrite the existing SDK files with the latest API definitions. |
140 | | - |
141 | | -##🌟 Method Naming Convention |
142 | | - |
143 | | -The generator creates clean, predictable method names: |
144 | | - |
145 | | -| API Endpoint| Generated Method| |
146 | | -|--------------|------------------| |
147 | | -|`GET /users`|`api200.users.getUsers.get()`| |
148 | | -|`GET /users/{id}`|`api200.users.getUsersById.get()`| |
149 | | -|`POST /users`|`api200.users.postUsers.post()`| |
150 | | -|`PUT /users/{id}`|`api200.users.putUsersById.put()`| |
151 | | -|`DELETE /users/{id}`|`api200.users.deleteUsersById.delete()`| |
152 | | - |
153 | | -##🔧 Configuration |
154 | | - |
155 | | -###Environment Variables |
156 | | -You can also use environment variables instead of command-line options: |
157 | | - |
158 | | -```bash |
159 | | -export API200_TOKEN=your_token_here |
160 | | -export API200_BASE_URL=https://eu.api200.co/api |
161 | | -export API200_OUTPUT=./lib/api200 |
| 91 | +##Error Handling |
162 | 92 |
|
163 | | -npx api200-generate-sdk |
164 | | -``` |
| 93 | +All API methods return a consistent response structure: |
165 | 94 |
|
166 | | -###Project Integration |
167 | | -Add generation to your package.json scripts: |
| 95 | +```typescript |
| 96 | +interfaceAPI200Response<T> { |
| 97 | + data:T|null; |
| 98 | + error:API200Error|null; |
| 99 | +} |
168 | 100 |
|
169 | | -```json |
170 | | -{ |
171 | | -"scripts": { |
172 | | -"generate-sdk":"api200-generate-sdk -t $API200_TOKEN", |
173 | | -"build":"npm run generate-sdk && tsc", |
174 | | -"dev":"npm run generate-sdk && npm run build -- --watch" |
175 | | - } |
| 101 | +interfaceAPI200Error { |
| 102 | + message:string; |
| 103 | + status?:number; |
| 104 | + details?:any; |
176 | 105 | } |
177 | 106 | ``` |
178 | 107 |
|
179 | | -##🐛 Troubleshooting |
180 | | - |
181 | | -###Common Issues |
182 | | - |
183 | | -**"Failed to fetch services" Error** |
184 | | -- Verify your API token is correct |
185 | | -- Check if the base URL is accessible |
186 | | -- Ensure you have internet connectivity |
187 | | - |
188 | | -**TypeScript Compilation Errors** |
189 | | -- Make sure you have TypeScript installed:`npm install -D typescript` |
190 | | -- Check that your tsconfig.json includes the generated files |
191 | | - |
192 | | -**Permission Errors** |
193 | | -- Ensure you have write permissions to the output directory |
194 | | -- Try running with elevated permissions if needed |
195 | | - |
196 | | -###Getting Help |
197 | | -- Check the[API 200](https://api200.co) documentation |
198 | | -- Open an issue on GitHub |
199 | | -- Contact support through the API 200 website |
200 | | - |
201 | | -##📄 License |
| 108 | +##Types |
202 | 109 |
|
203 | | -MIT License - see the[LICENSE](LICENSE) filefordetails. |
| 110 | +The generator creates comprehensive TypeScript typesforall your APIs: |
204 | 111 |
|
205 | | -##🔗 Links |
| 112 | +##Updating Your SDK |
206 | 113 |
|
207 | | --**[API 200 Website](https://api200.co)** - Main service website |
208 | | --**[API Documentation](https://api200.co/docs)** - Full API documentation |
209 | | --**[GitHub Repository](https://github.com/your-org/api200-sdk-generator)** - Source code and issues |
| 114 | +When you add new services or modify existing ones in API200: |
210 | 115 |
|
211 | | -##🤝 Contributing |
| 116 | +1.**Regenerate the SDK**: |
| 117 | +```bash |
| 118 | + npx api200-generate-sdk -t YOUR_API_TOKEN |
| 119 | +``` |
212 | 120 |
|
213 | | -Contributions are welcome! Please feel free to submit a Pull Request. |
| 121 | +2.**The generator will**: |
| 122 | +- Fetch the latest service definitions |
| 123 | +- Update all type definitions |
| 124 | +- Add new service methods |
| 125 | +- Preserve your existing configuration |
214 | 126 |
|
215 | | -1. Fork the repository |
216 | | -2. Create your feature branch (`git checkout -b feature/amazing-feature`) |
217 | | -3. Commit your changes (`git commit -m 'Add some amazing feature'`) |
218 | | -4. Push to the branch (`git push origin feature/amazing-feature`) |
219 | | -5. Open a Pull Request |
| 127 | +3.**No breaking changes**: Existing code continues to work while new features become available |
220 | 128 |
|
221 | | ---- |
| 129 | +##Support |
222 | 130 |
|
223 | | -**Made with ❤️ for[API 200](https://api200.co) developers** |
| 131 | +-[GitHub](https://github.com/API-200/api200/discussions) |