npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

redux-axios-jwt

v0.0.3

Published

Boilerplate for REST apis.

Downloads

2

Readme

redux-axios-jwt

Kind of like a boilerplate. Plug and play, use with DJango, DRF Rest APIs.

Setting up

Installing package using NPM.

npm install redux-axios-jwt

Once installed, you know need to link package with your application.

Note: Before setting up make sure you have redux setup already.

Defining URL & AuthKey (Example)

Default URL value is https://localhost:3000

Open main parent index.js file and add following lines of code.

...
import setURL form 'redux-axios-jwt'

let URL = 'http://localhost:8000/api' // server url for the apis
let AuthKey = "Basic" // Key value for Authorization in Headers.
setURL(URL, AuthKey)
...
API setURL()

| Name | Type | Default | Description | | ------- | ------ | ------------------------- | ---------------------------------------------------- | | URL | string | "http://localhost:3000" | Server URL, call to be made to. | | AuthKey | string | "Basic" | Key value required for JWT Authorization in headers' |

API Actions / Reducers

To use apiAction, you first need to link its reducers with the store. Open reducers index.js file and add in following lines.

...
import apiReducers from  "redux-axios-jwt/reducers/apiReducers";

export default combineReducers({
    ...
    api: apiReducers,
    ...
});
...

Actions List

| Name | Params | Type | Params Defaults | Description | State|
| ------------------- | --------------------------------------------------- | --------------------------------------------------- | ---------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ---------------------------------------------------------------------- | | isLoading | status | Boolean | false | This action runs by default (if stateLoading = true), enabling to be run at parent component level. This is linked with each action that makes an Axios call, hence follows following rules. Before axios call => trueOnce returns a callback => falselet loading = useState((state) => state.api.isLoading) | api.isLoading | | returnMsg | message | string | "" | This action runs by default, enabling to be run at parent component level.This is linked with each action that makes an Axios call, hence follows following rules.Once returns a callback => msg from .then response.status_code.catch error.response.statuslet msg = useState((state) => state.api.message) | api.message
| isUniversal | data | object | {} | Get data inform of an objectCan be accessed from anywhere.let universal = useState((state) => state.api.universal) | api.universal
| changeValue | namevalue | stringobject | | Stores any value against a key. Can be used in forms as handleChange. Can be accessed from anywhere.let value = useState((state) => state.api.value) | api.value
| resetValue | | | | Reset value of redux to default. Can be used once you are done using value param, for e.g. after completing form and submitting it to the post request. Its not called automatically by any other action. | | | postData | datalinktokenstateLoading | objectstringstringboolean | true | Sends post request and returns with an error or request. et value = useState((state) => state.api[link]) | api[link]
| getData | paramslinktokenstateLoading | stringstringstringboolean | true | Sends get request and returns with an error or request. | api["GET-" + link]
| getListData | linktokenstateLoading | stringstringboolean | true | Sends get request and returns with an error or request. | api[link]
| putDataParams | datalinkparamstokenstateLoading | objectstringstringstringboolean | true | Sends put request with data and returns with an error or request. | | putDataSimple | datalinktokenstateLoading | objectstringstringboolean | true | Sends put request with data and returns with an error or request. | api[link]
| searchData | paramslinktokenstateLoading | stringstringstringboolean | true | Sends get request with search params and returns with an error or request. | api[link]
| deleteData | paramslinktokenstateLoading | stringstringstringboolean | stringstringstringboolean | true | Sends delete request with params and returns with an error or request. | api[link]

API Actions / Reducers

To use userActions, you first need to link its reducers with the store. Open reducers index.js file and add in following lines.

...
import userReducers from  "redux-axios-jwt/reducers/userReducers";

export default combineReducers({
    ...
    user: userReducers,
    ...
});
...

Actions List

| Name | Params | Type | Params Defaults | Description | State|
| ------------------- | --------------------------------------------------- | --------------------------------------------------- | ---------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ---------------------------------------------------------------------- | | isLoading | status | Boolean | false | This action runs by default (if stateLoading = true), enabling to be run at parent component level. This is linked with each action that makes an Axios call, hence follows following rules. Before axios call => trueOnce returns a callback => falselet loading = useState((state) => state.user.isLoading) | user.isLoading | | returnMsg | message | string | "" | This action runs by default, enabling to be run at parent component level.This is linked with each action that makes an Axios call, hence follows following rules.Once returns a callback => msg from .then response.status_code.catch error.response.statuslet msg = useState((state) => state.user.message) | user.message
| changeValue | namevalue | stringobject | | Stores any value against a key. Can be used in forms as handleChange. Can be accessed from anywhere.let value = useState((state) => state.user.value) | user.value
|firstTimeLoad||||Insert at the time when app renders for the first time. User auth credentials gets loaded on first time load, hence automatically logins.| |loginUser|userNamepassworduserDetailsLink|stringstringstring|"accounts/getuser/"|Login user using username and password.On success gets token and refresh token which than gets stored in localstorage. Send an api call to get userdetails too. Gets stored in user_data.|user.id_tokenuser.user_data

Contributar

Hamza Fayyaz