Skip to content

Commit eabf6d9

Browse files
committed
Update README.md
1 parent c8b5926 commit eabf6d9

File tree

9 files changed

+1026
-114
lines changed

9 files changed

+1026
-114
lines changed

README.md

Lines changed: 268 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,26 @@
1-
# devup API
1+
# devup-api
2+
3+
[![npm version](https://img.shields.io/npm/v/@devup-api/fetch.svg)](https://www.npmjs.com/package/@devup-api/fetch)
4+
[![npm downloads](https://img.shields.io/npm/dm/@devup-api/fetch.svg)](https://www.npmjs.com/package/@devup-api/fetch)
5+
[![npm bundle size](https://img.shields.io/bundlephobia/minzip/@devup-api/fetch)](https://bundlephobia.com/package/@devup-api/fetch)
6+
[![License](https://img.shields.io/badge/license-Apache--2.0-blue.svg)](LICENSE)
7+
[![GitHub Actions](https://img.shields.io/github/actions/workflow/status/dev-five-git/devup-api/publish.yml?branch=main&label=CI)](https://github.com/dev-five-git/devup-api/actions)
8+
[![Codecov](https://img.shields.io/codecov/c/github/dev-five-git/devup-api)](https://codecov.io/gh/dev-five-git/devup-api)
9+
[![GitHub stars](https://img.shields.io/github/stars/dev-five-git/devup-api.svg?style=social&label=Star)](https://github.com/dev-five-git/devup-api)
10+
[![GitHub forks](https://img.shields.io/github/forks/dev-five-git/devup-api.svg?style=social&label=Fork)](https://github.com/dev-five-git/devup-api/fork)
11+
[![GitHub issues](https://img.shields.io/github/issues/dev-five-git/devup-api.svg)](https://github.com/dev-five-git/devup-api/issues)
12+
[![GitHub pull requests](https://img.shields.io/github/issues-pr/dev-five-git/devup-api.svg)](https://github.com/dev-five-git/devup-api/pulls)
13+
[![GitHub last commit](https://img.shields.io/github/last-commit/dev-five-git/devup-api.svg)](https://github.com/dev-five-git/devup-api/commits/main)
14+
[![TypeScript](https://img.shields.io/badge/TypeScript-5.9-blue.svg)](https://www.typescriptlang.org/)
15+
[![Bun](https://img.shields.io/badge/Bun-latest-000000.svg)](https://bun.sh)
16+
[![Biome](https://img.shields.io/badge/Biome-2.3-000000.svg)](https://biomejs.dev)
17+
[![Node.js](https://img.shields.io/badge/Node.js-18%2B-green.svg)](https://nodejs.org/)
18+
[![OpenAPI](https://img.shields.io/badge/OpenAPI-3.1-green.svg)](https://www.openapis.org/)
219

320
**A fully typed API client generator powered by OpenAPI.
421
Fetch-compatible, auto-generated types, zero generics required.**
522

6-
devup API reads your `openapi.json` file and automatically generates a fully typed client that behaves like an ergonomic, type-safe version of `fetch()`.
23+
devup-api reads your `openapi.json` file and automatically generates a fully typed client that behaves like an ergonomic, type-safe version of `fetch()`.
724
No manual type declarations. No generics. No SDK boilerplate.
825
Just write API calls — the types are already there.
926

@@ -17,115 +34,318 @@ Just write API calls — the types are already there.
1734
- No need to write or maintain separate TypeScript definitions.
1835

1936
### **🪝 Fetch-compatible design**
20-
devup API feels like using `fetch`, but with superpowers:
37+
devup-api feels like using `fetch`, but with superpowers:
2138

2239
- Path params automatically replaced
2340
- Query/body/header types enforced
2441
- Typed success & error responses
2542
- Optional runtime schema validation
2643
- Minimal abstraction over standard fetch
2744

45+
### **🔌 Build tool integration**
46+
- Works seamlessly with Vite, Next.js, Webpack, and Rsbuild
47+
- Automatic type generation during build time
48+
- Zero runtime overhead
49+
2850
---
2951

3052
## 🚀 Quick Start
3153

32-
### **1. Initialize the client**
54+
### **1. Install the package**
55+
56+
```bash
57+
# For Vite projects
58+
npm install @devup-api/fetch @devup-api/vite-plugin
59+
60+
# For Next.js projects
61+
npm install @devup-api/fetch @devup-api/next-plugin
62+
63+
# For Webpack projects
64+
npm install @devup-api/fetch @devup-api/webpack-plugin
65+
66+
# For Rsbuild projects
67+
npm install @devup-api/fetch @devup-api/rsbuild-plugin
68+
```
69+
70+
### **2. Configure your build tool**
71+
72+
**Vite** (`vite.config.ts`):
73+
```ts
74+
import { defineConfig } from 'vite'
75+
import devupApi from '@devup-api/vite-plugin'
76+
77+
export default defineConfig({
78+
plugins: [devupApi()],
79+
})
80+
```
81+
82+
**Next.js** (`next.config.ts`):
83+
```ts
84+
import devupApi from '@devup-api/next-plugin'
85+
86+
export default devupApi({
87+
reactStrictMode: true,
88+
})
89+
```
90+
91+
**Webpack** (`webpack.config.js`):
92+
```js
93+
const { devupApiWebpackPlugin } = require('@devup-api/webpack-plugin')
94+
95+
module.exports = {
96+
plugins: [new devupApiWebpackPlugin()],
97+
}
98+
```
3399

100+
**Rsbuild** (`rsbuild.config.ts`):
34101
```ts
35-
import { devupApi } from "devup-api";
102+
import { defineConfig } from '@rsbuild/core'
103+
import { devupApiRsbuildPlugin } from '@devup-api/rsbuild-plugin'
104+
105+
export default defineConfig({
106+
plugins: [devupApiRsbuildPlugin()],
107+
})
108+
```
109+
110+
### **3. Add your OpenAPI schema**
111+
112+
Place your `openapi.json` file in the project root (or specify a custom path in plugin options).
113+
114+
### **4. Configure TypeScript**
36115

37-
// create api instance
38-
const api = devupApi("https://api.example.com");
116+
Add the generated type definitions to your `tsconfig.json`:
117+
118+
```json
119+
{
120+
"compilerOptions": {
121+
// ... your compiler options
122+
},
123+
"include": [
124+
"src",
125+
"df/**/*.d.ts"
126+
]
127+
}
39128
```
40129

41-
### **2. Call endpoints — types are automatic**
130+
> **Note:** The `df` directory is the default temporary directory where generated types are stored. If you've customized `tempDir` in plugin options, adjust the path accordingly (e.g., `"your-temp-dir/**/*.d.ts"`).
131+
132+
### **5. Create and use the API client**
42133

43134
```ts
44-
const user = await api.get("/users/{id}", {
45-
params: { id: "123" },
135+
import { createApi } from '@devup-api/fetch'
136+
137+
const api = createApi('https://api.example.com')
138+
139+
// Use operationId
140+
const users = await api.get('getUsers', {})
141+
142+
// Or use the path directly
143+
const user = await api.get('/users/{id}', {
144+
params: { id: '123' },
46145
headers: {
47-
Authorization: "Bearer TOKEN"
146+
Authorization: 'Bearer TOKEN'
48147
}
49-
});
148+
})
50149

51-
const user = await api.get("getUser", {
52-
params: { id: "123" },
53-
headers: {
54-
Authorization: "Bearer TOKEN"
150+
// POST request with typed body
151+
const newUser = await api.post('createUser', {
152+
body: {
153+
name: 'John Doe',
154+
email: 'john@example.com'
55155
}
56-
});
156+
})
57157
```
58158

59159
---
60160

61-
## 📦 Installation
161+
## 🔥 Cold Typing vs Bold Typing
62162

63-
```bash
64-
npm install @devup-api/fetch
163+
devup-api uses a two-phase typing system to ensure smooth development experience:
65164

66-
npm install @devup-api/next-plugin
67-
npm install @devup-api/webpack-plugin
68-
npm install @devup-api/rsbuild-plugin
69-
npm install @devup-api/vite-plugin
165+
### **Cold Typing**
166+
167+
**Cold typing** refers to the state before the TypeScript interface files are generated. This happens when:
168+
- You first install the plugin
169+
- The build hasn't run yet
170+
- The generated `api.d.ts` file doesn't exist
171+
172+
During cold typing:
173+
- All API types are treated as `any`
174+
- Type checking is relaxed to prevent type errors
175+
- Your code will compile and run without issues
176+
- You can write API calls without waiting for type generation
177+
178+
```ts
179+
// Cold typing: No type errors even if api.d.ts doesn't exist yet
180+
const api = createApi('https://api.example.com')
181+
const result = await api.get('getUsers', {}) // ✅ Works, types are 'any'
182+
```
183+
184+
### **Bold Typing**
185+
186+
**Bold typing** refers to the state after the TypeScript interface files are generated. This happens when:
187+
- The build tool has run (`dev` or `build`)
188+
- The plugin has generated `api.d.ts` in the temp directory
189+
- TypeScript can find and use the generated types
190+
191+
During bold typing:
192+
- All API types are strictly enforced
193+
- Full type safety is applied
194+
- Type errors will be caught at compile time
195+
- You get full IntelliSense and autocomplete
196+
197+
```ts
198+
// Bold typing: Full type safety after api.d.ts is generated
199+
const api = createApi('https://api.example.com')
200+
const result = await api.get('getUsers', {})
201+
// ✅ Fully typed: result.data is typed based on your OpenAPI schema
202+
// ❌ Type error if you use wrong parameters or paths
70203
```
71204

205+
### **Why This Matters**
206+
207+
This two-phase approach ensures:
208+
1. **No blocking**: You can start coding immediately without waiting for the build
209+
2. **Gradual typing**: Types become available as soon as the build runs
210+
3. **Production safety**: Full type checking in production builds
211+
4. **Developer experience**: No false type errors during initial setup
212+
213+
---
214+
215+
## 📦 Packages
216+
217+
This is a monorepo containing multiple packages:
218+
219+
- **`@devup-api/core`** - Core types and interfaces
220+
- **`@devup-api/utils`** - Utility functions for OpenAPI processing
221+
- **`@devup-api/generator`** - TypeScript interface generator from OpenAPI schemas
222+
- **`@devup-api/fetch`** - Type-safe API client
223+
- **`@devup-api/vite-plugin`** - Vite plugin
224+
- **`@devup-api/next-plugin`** - Next.js plugin
225+
- **`@devup-api/webpack-plugin`** - Webpack plugin
226+
- **`@devup-api/rsbuild-plugin`** - Rsbuild plugin
227+
72228
---
73229

74230
## 📚 API Usage
75231

76232
### **GET Example**
77233

78234
```ts
79-
await api.get("/posts", {
235+
// Using operationId
236+
const users = await api.get('getUsers', {
237+
query: { page: 1, limit: 20 }
238+
})
239+
240+
// Using path
241+
const users = await api.get('/users', {
80242
query: { page: 1, limit: 20 }
81-
});
243+
})
82244
```
83245

84246
### **POST Example**
85247

86248
```ts
87-
await api.post("/posts", {
249+
const newPost = await api.post('createPost', {
88250
body: {
89-
title: "Hello World",
90-
content: "This is a typed API request."
251+
title: 'Hello World',
252+
content: 'This is a typed API request.'
91253
}
92-
});
254+
})
93255
```
94256

95257
### **Path Params Example**
96258

97259
```ts
98-
await api.get("/posts/{id}", {
99-
params: { id: "777" }
100-
});
260+
const post = await api.get('/posts/{id}', {
261+
params: { id: '777' }
262+
})
263+
```
264+
265+
### **Response Handling**
266+
267+
```ts
268+
const result = await api.get('getUser', { params: { id: '123' } })
269+
270+
if (result.data) {
271+
// Success response - fully typed!
272+
console.log(result.data.name)
273+
} else if (result.error) {
274+
// Error response
275+
console.error(result.error.message)
276+
}
101277
```
102278

103279
---
104280

105-
## ⚙️ How It Works
281+
## ⚙️ Configuration Options
282+
283+
All plugins accept the following options:
106284

107-
1. Download `openapi.json`
108-
2. Extract paths, methods, schemas, parameters, bodies
109-
3. Generate TypeScript types automatically
110-
4. Build a typed wrapper around `fetch()`
111-
5. Expose methods based on the API structure
285+
```ts
286+
interface DevupApiOptions {
287+
/**
288+
* OpenAPI file path
289+
* @default 'openapi.json'
290+
*/
291+
openapiFile?: string
292+
293+
/**
294+
* Temporary directory for storing generated files
295+
* @default 'df'
296+
*/
297+
tempDir?: string
298+
299+
/**
300+
* Case conversion type for API endpoint names and parameters
301+
* @default 'camel'
302+
*/
303+
convertCase?: 'snake' | 'camel' | 'pascal' | 'maintain'
304+
305+
/**
306+
* Whether to make all properties non-nullable by default
307+
* @default false
308+
*/
309+
requestDefaultNonNullable?: boolean
310+
311+
/**
312+
* Whether to make all request properties non-nullable by default
313+
* @default true
314+
*/
315+
responseDefaultNonNullable?: boolean
316+
}
317+
```
112318

113319
---
114320

115-
## 🎯 Why devup API?
321+
## 🎯 How It Works
116322

117-
- No code generators
118-
- No build steps
119-
- No boilerplate
120-
- Uses OpenAPI schema directly
121-
- Works in Next.js, Bun, Vite, rsbuild
323+
1. Plugin reads your `openapi.json` during build time
324+
2. Extracts paths, methods, schemas, parameters, and request bodies
325+
3. Generates TypeScript interface definitions automatically
326+
4. Creates a URL map for operationId-based API calls
327+
5. Builds a typed wrapper around `fetch()` with full type safety
122328

123329
---
124330

125-
## 🛠️ Roadmap
331+
## 🛠️ Development
332+
333+
```bash
334+
# Install dependencies
335+
bun install
336+
337+
# Build all packages
338+
bun run build
339+
340+
# Run tests
341+
bun test
126342

127-
- [ ] Typescript interface generation
128-
- [ ] Zod schema generation
343+
# Lint
344+
bun run lint
345+
346+
# Fix linting issues
347+
bun run lint:fix
348+
```
129349

130350
---
131351

0 commit comments

Comments
 (0)