Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit1aea5fb

Browse files
committed
update sdk readme
1 parent450d00a commit1aea5fb

File tree

1 file changed

+80
-172
lines changed

1 file changed

+80
-172
lines changed

‎packages/js-sdk/README.md‎

Lines changed: 80 additions & 172 deletions
Original file line numberDiff line numberDiff line change
@@ -1,223 +1,131 @@
11
#API200 SDK Generator
22

3-
[![npm version](https://badge.fury.io/js/api200-sdk-generator.svg)](https://badge.fury.io/js/api200-sdk-generator)
4-
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](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.
54

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
76

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
914

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
1616

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
1820

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):
2324

24-
###One-time Usage (Recommended)
2525
```bash
26-
npx api200-generate-sdk -tyour_api_token
26+
npx api200-generate-sdk -tYOUR_API_TOKEN
2727
```
2828

29-
##🛠️ Usage
29+
##Command Options
3030

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`|
3536

36-
###Custom Output Directory
37-
```bash
38-
npx api200-generate-sdk -t YOUR_API_TOKEN -o ./src/api
39-
```
37+
###Examples
4038

41-
###Custom Base URL
4239
```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
4542

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
4945

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
5548
```
5649

57-
##📁Generated Structure
50+
##Generated Structure
5851

59-
The generator createsa clean, organized SDK structure:
52+
TheSDKgenerator createsthe following file structure:
6053

6154
```
6255
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
6860
```
6961

70-
##💻 Usage Examples
62+
##Usage Example
63+
64+
###Usage
7165

72-
###Basic Import and Usage
7366
```typescript
74-
import{api200 }from'./lib/api200';
67+
importapi200from'./lib/api200';
7568

7669
// 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"
8572
});
8673

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);
10878
}
10979
```
11080

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
13082

131-
##🔄 Updating Your SDK
83+
Methods are generated using the pattern:`[httpMethod][EndpointPath]`
13284

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()`
13490

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
16292

163-
npx api200-generate-sdk
164-
```
93+
All API methods return a consistent response structure:
16594

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+
}
168100

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;
176105
}
177106
```
178107

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
202109

203-
MIT License - see the[LICENSE](LICENSE) filefordetails.
110+
The generator creates comprehensive TypeScript typesforall your APIs:
204111

205-
##🔗 Links
112+
##Updating Your SDK
206113

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:
210115

211-
##🤝 Contributing
116+
1.**Regenerate the SDK**:
117+
```bash
118+
npx api200-generate-sdk -t YOUR_API_TOKEN
119+
```
212120

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
214126

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
220128

221-
---
129+
##Support
222130

223-
**Made with ❤️ for[API 200](https://api200.co) developers**
131+
-[GitHub](https://github.com/API-200/api200/discussions)

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp