JSPM

rest-set-cli

1.0.0
    • ESM via JSPM
    • ES Module Entrypoint
    • Export Map
    • Keywords
    • License
    • Repository URL
    • TypeScript Types
    • README
    • Created
    • Published
    • Downloads 6
    • Score
      100M100P100Q27306F
    • License ISC

    CLI to scaffold REST client setup for React and Next.js apps

    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)
    • Installs axios
    • Creates src/services/ (or root services/ if src is missing)
    • Generates:
      • api.js / api.ts
      • endpoints.js / endpoints.ts
      • userService.js / userService.ts
    • Generates both REST clients in api:
      • publicApi for public endpoints (no token)
      • privateApi for authenticated endpoints (Authorization header)
    • Optionally creates src/components/DemoComponent.jsx / .tsx
    • Basic loading and error handling in demo usage

    Usage

    npx rest-set-cli

    Example 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.tsx

    Notes

    • privateApi automatically reads the token using your selected storage and key name, and attaches it as Bearer <token> in request headers.
    • userService contains sample usage of both clients:
      • public call: fetchUsers() via publicApi
      • private call: fetchUserById(id) via privateApi
    • For Next.js, the CLI prints a basic router detection message (app or pages) as groundwork for future folder-level customization.
    • Future enhancements can include swr / react-query, fetch-based client setup, and generated hooks like useUserData().