I'm writing small client-side blazor app. To avoid using any DB (and creating whole API for it), as I have basically just a list of single class objects, I wanted to use json file.
I know I can read from file:
forecasts = await Http.GetFromJsonAsync<WeatherForecast[]>("sample-data/weather.json");
But when I modify this "forecasts" list and try to do something like this:
await Http.PostAsJsonAsync("sample-data/weather.json", forecasts);
or
await Http.PostAsJsonAsync<WeatherForecast[]>("sample-data/weather.json", forecasts);
It is not saving changes. I checked in browser and it is doing a POST with correct data, but receives 404 in return. Is it possible to save such a data after modification?
What you are trying to do is to change a file on server from a application that lives on the users browser. When the user visits you blazor site all of the files (except the ones that are set for lazy loading) are downloaded into the user browser. After the applications lives and runs in the users browser.
If you don't need any concurrency check and real database capabilities you should build some simple server that allows static file access or other option is to use simple blob access from AWS S3 or Azure Blob Storage.
You can look up here the difference between client and server side Blazor. If you need to share persistent data between multiple clients you will need to implement a server or service that will allow this for you if you use client side Blazor.