Thanks to visit codestin.com
Credit goes to github.com

Skip to content
/ defjs Public

πŸ‘ Defjs is a library that helps you define and initiate requests, aiming to make it easier for you to define requests without worrying about the details.

License

Notifications You must be signed in to change notification settings

defjs/defjs

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

35 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

🚧 Coming soon 1.0 design

design.md


logo


npm package monthly downloads build status license codecov


Introduction

def is an abbreviation for define, so it can be read as define js.

Defjs is a library that helps you define and initiate requests, aiming to make it easier for you to define requests without worrying about the details.

  • Supports multiple request methods such as Fetch, XMLHttpRequest, custom, etc.
  • Functional API.
  • 🚧 Supports streaming. (WIP)
  • Supports JS/TS with complete type.
  • Supports any JS runtime.
  • Supports Interceptors.
  • Supports ESM
  • 🚧 Supports Mini Programs. (WIP)

Quick Start

Use for package manager

npm install @defjs/core
// or
yarn install @defjs/core
// or
pnpm install @defjs/core
// or
bun install @defjs/core

Use for CDN

Only can use ES modules

import {
  createGlobalClient,
  defineRequest, 
  field
} from 'https://unpkg.com/@defjs/core/index.min.js';

/**
 * @title Step 1
 * @file src/main.ts
 * @description Setting up a global client
 */
createGlobalClient({
  host: 'https://example.com',
});

/**
 * @title Step 2
 * @file src/lib/api/user.ts
 * @description Define the request api request in the lib/api directory of the project
 */
const useGetUser = defineRequest('/v1/user/:id')
  .withField({
    id: field<number>().withParam()
  })

/**
 * @title Step 3
 * @file src/pages/home.ts
 * @description Use defined requests in business code
 */
const { doRequest } = useGetUser();
const { error, body } = await doRequest({id: 1});
if (error) {
  console.error(error);
  return;
}
console.log(body);

Documentation

Check out the 🚧 defjs.org to get started.

Packages

Package Version
@defjs/core core version
@defjs/angular core version

Roadmap

  • Documentation official website
  • Wechat mini programs handler
  • CLI Tool
    • Generate API from OpenAPI
    • Generate Full SDK Package (Like the S3 SDK)
  • Vue wrapper package
  • React wrapper package
  • Think about simplifying useXXX and doRequest

License

MIT

Reference

About

πŸ‘ Defjs is a library that helps you define and initiate requests, aiming to make it easier for you to define requests without worrying about the details.

Topics

Resources

License

Code of conduct

Stars

Watchers

Forks

Sponsor this project

 

Packages

No packages published