Skip to content

Repository files navigation

http-schema

A parser for HTTP schema DSL, supporting RESTful APIs and path parsing.

version license download

Installation

yarn add @jswork/http-schema

Quick Start

// 1. Define your API schema
// schema.ts
export default {
  baseURL: '/api',
  request: ['', 'json'],
  items: [
    { resources: ['badges'] },
    {
      request: ['/v1', 'json'],
      items: { profile: ['get', '/me'] }
    }
  ]
};

// 2. Create API instance
// api.ts
import httpSchema from '@jswork/http-schema';
import { FetchAdapter } from '@jswork/universal-request-adapter-fetch';
import schema from './schema';

const api = httpSchema(schema, {
  adapter: new FetchAdapter(),
});

// 3. Use the API
await api.badges_index();       // GET /api/badges
await api.badges_show({ id: 1 });  // GET /api/badges/1
await api.profile();            // GET /api/v1/me

Features

# Doc Description
01 Basic Usage DSL 定义 & 创建 API 实例
02 RESTful Resources CRUD 自动生成
03 Typed API 多业务线同构接口
04 Path Params 路径占位符 {id} / :param
05 Prefix & Suffix 函数名前缀/后缀
06 Interceptors 请求拦截器 & transformResponse
07 Schema Config 完整配置项参考
08 DSL Rules 全套 DSL 规则参考

Monorepo Structure

http-schema/
├── packages/
│   └── core/          # Core library (@jswork/http-schema)
│       ├── src/       # Source code
│       ├── __tests__/ # Tests
│       └── package.json
├── apps/
│   └── example/       # Demo application (Vite + React)
└── docs/              # Specifications, plans, and feature docs

License

Code released under the MIT license.

About

A parser for HTTP schema DSL, supporting RESTful APIs and path parsing.

Topics

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages