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.