Package Exports
- rest-set-cli
- rest-set-cli/index.js
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (rest-set-cli) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
REST Set CLI
Automate REST client setup in React and Next.js projects.
Features
- Interactive CLI prompts for:
- framework (
React/Next.js) - language (
JavaScript/TypeScript) - token storage (
localStorage/cookie) - token variable name (example:
authToken,token,TokenValue)
- framework (
- Installs
axios - Creates
src/services/(or rootservices/ifsrcis missing) - Generates:
api.js/api.tsendpoints.js/endpoints.tsuserService.js/userService.ts
- Generates both REST clients in
api:publicApifor public endpoints (no token)privateApifor authenticated endpoints (Authorizationheader)
- Optionally creates
src/components/DemoComponent.jsx/.tsx - Basic loading and error handling in demo usage
Usage
npx rest-set-cliExample Flow
? Which framework are you using? (React/Next.js)
> React
? What language are you using? (JavaScript/TypeScript)
> TypeScript
? Where do you want to store auth token? (localStorage/Cookie)
> localStorage
? Enter token variable name (example: authToken, token, TokenValue):
> authToken
? Do you want to generate a demo component? (Y/n)
> Yes
[+] Installing dependencies: axios
[✓] Created src/services/api.ts
[✓] Created src/services/endpoints.ts
[✓] Created src/services/userService.ts
[✓] Created src/components/DemoComponent.tsxNotes
privateApiautomatically reads the token using your selected storage and key name, and attaches it asBearer <token>in request headers.userServicecontains sample usage of both clients:- public call:
fetchUsers()viapublicApi - private call:
fetchUserById(id)viaprivateApi
- public call:
- For Next.js, the CLI prints a basic router detection message (
apporpages) as groundwork for future folder-level customization. - Future enhancements can include
swr/react-query,fetch-based client setup, and generated hooks likeuseUserData().