rest-set-cli
v1.0.0
Published
CLI to scaffold REST client setup for React and Next.js apps
Maintainers
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().
