@sleegle/sthore

1.1.3 • Public • Published

alt text

Sthore: Connect back-end API to react project with one command

Create your sthore-config file, put it in your project folder and run "sthore" command. BANG! it will create a Redux-Saga based store and generate API Services files for your project and you can fully customize it :) JUST ENJOY AND CHILL!

You can see Demo Here. Files src/stores and src/services folders are auto generated using sthore with sthore.config.json file in project root.

Installation

npm install @sleegle/sthore -g

or

yarn global add @sleegle/sthore

Usage

  1. Create your sthore.config.json file in project root

sthore.config.json template

{
  "baseURL": "https://your_base_url",     // Backend URL
  "storesDir": "src/stores",              // Stores folder direction
  "servicesDir": "src/services",          // Services folder direction
  "stores": [
    {
      "name": "auth",               // Store name
      "actions": [                  // Store actions
        {
          "name": "login",          // Action name
          "url": "/auth/login",     // Action URL path
          "method": "POST",         // Action method
          "storage": [              // Response data that you want to put it in local storage
            "accessToken",          // For example response is {"accessToken" : "...", efreshToken":"..."}
            "refreshToken"
          ]
        },
        {
          "name": "user",
          "url": "/auth/user",
          "method": "GET"
        }
      ]
    },
    {
      "name": "users",
      "actions": [
        {
          "name": "getAll",
          "url": "/users",
          "method": "GET"
        },
        {
          "name": "single",
          "url": "/users/${id}",      // If you have dynamic rams in your request,
                                      // just put them in l like this "${param}
          "method": "GET"
        },
        {
          "name": "create",
          "url": "/users",
          "method": "POST"
        },
        {
          "name": "update",
          "url": "/users/${id}",
          "method": "PUT"
        },
        {
          "name": "remove",
          "url": "/users/${id}",
          "method": "DELETE"
        }
      ]
    }
  ]
}
  1. Run sthore command

  2. Your js files are generated

Package Sidebar

Install

npm i @sleegle/sthore

Weekly Downloads

0

Version

1.1.3

License

MIT

Unpacked Size

28 kB

Total Files

19

Last publish

Collaborators

  • ramtinsh
  • hamidrebor