Skip to content
This repository has been archived by the owner on Dec 30, 2022. It is now read-only.

Example of a react-redux frontend using redux-axios-middleware that calls a .NET Core Web API

Notifications You must be signed in to change notification settings

Odonno/react-redux-axios-middleware-netcore-example

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 

Repository files navigation

react-redux-axios-middleware-netcore-example

Example of a react-redux frontend using redux-axios-middleware that calls a .NET Core Web API

Front

The frontend is written in react with a redux architecture. Actions and reducers can handle APi calls thank to redux-axios-middleware.

Actions

Here is an example of a single action handling both request and response from the API.

Request action

{
    type: 'API_CALL_NAME',
    payload: {
        request: AxiosRequestConfig
    }
}

Response action

success action

{
    type: 'API_CALL_SUCCESS',
    payload: AxiosResponse
}

fail action

{
    type: 'API_CALL_FAIL',
    payload: AxiosResponse
}

Reducers

Request reducer

In general, you should avoid using request reducer to update the state.

Depending on your use cases, request reducer can be directly used to give the feeling that the request has already been handled by the server. In case it doesn't, the FAIL action should be used to alert the user that there was a failure.

case Actions.INCREMENT:
    return {
        ...state,
        values: state.values.map(v => {
            if (v.name === action.payload.request.data.valueName) {
                return {
                    ...v,
                    value: v.value + 1
                };
            }

            return v;
        })
    };

Response reducer

case Actions.GET_VALUES_SUCCESS:
    return {
        ...state,
        values: action.payload.data
    };

Back

The backend is written using ASP.NET Core. It simply contains API routes used by the frontend.

Example 1 : counter with increment/decrement actions

Example of a web app that use simple API requests : increment or decrement named values.

About

Example of a react-redux frontend using redux-axios-middleware that calls a .NET Core Web API

Topics

Resources

Stars

Watchers

Forks