1

I'm using react-query for data operations and using asp.net Core Web Api for backend. I tried to fetch data by invoking a controller method but, it returned 'Status with 404 not found' error. I tried different ways but nothing seems to work. What's I'm doing wrong here ?

App.js

const queryProvider = new QueryClient();

function App(){
  return(
     <QueryClientProvider client={queryProvider}>
        <Test />
        <ReactQueryDevtools/>
     </QueryClientProvider>
   );
}

function Test() {
    const { isLoading, error, data, isFetching } = useQuery("fetchKey", () =>
        axios.get(
            "https://localhost:7036/api/general/getmaturedata"
        ).then((res) => res.data)
    );

    if (isLoading) return "Loading...";

    if (error) return "An error has occurred: " + error.message;
}

Controller.cs

[ApiController]
public class GeneralController : ControllerBase
{
        [Route("api/general/getmaturedata")]
        [HttpPost]

        public IActionResult GetMatureData()
        {
            return new JsonResult(true);
        }
}

launchSettings.json

"profiles": {
     "applicationUrl": "https://localhost:7036;http://localhost:5036",
     "dotnetRunMessages": true
}

Note: I'm trying to hit a Debugger point in the controller method in order to test whether the code works or not. There are no data is provided yet.

4
  • If you open the URL you are trying to get in a new tab, does it also give you a 404? Commented May 25, 2022 at 21:19
  • @JakubKotrs Yes it does Commented May 26, 2022 at 6:45
  • In that case, it's not a problem on the frontend with React and/or React Query. You could simplify the question to ASP.net only. (Sorry, I came here for the frontend tags.) Commented May 26, 2022 at 7:54
  • @JakubKotrs Thanks for pointing that out ... I will simplify the question Commented May 26, 2022 at 9:45

1 Answer 1

1

I found the solution.

As @JakubKotrs mentioned it was not on react-query but, web API itself. I changed the controller and router respectively and solved the problem

similar answer is given here

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.