I am looking for a way to cache the response from a http get request and everytime the user opens the app i want to compare the data in the cache with the data from the request and display the http response instead of the cached data if there is any difference
You should try using the package flutter_cache_manager, that should fit your needs.
Related
Let's say I log into an api with my flutter app. In an website, they automatically store the login cookie and then can use it. But in flutter app, how do I store the cookies and session? And how do I pass that into post to let the api know I have a valid login session?
Q: It's making me more confused, I just want the part to extract
cookie and how to use it.
There are a number of complexities, depending on exactly what you ultimately want to do.
But let's assume:
Your Flutter app makes an HTTP request (GET, PUT, etc.)
The server (e.g. your Flask app) returns cookies in the HTTP response (in the HTTP response header).
Let's further assume your HTTP code looks something like this:
Future<http.Response> fetchAlbum() {
return http.get(Uri.parse('https://jsonplaceholder.typicode.com/albums/1'));
}
In that case, you should be able to reference the cookies property of the Response object returned from the server.
SUGGESTION: See also these links:
Flutter For Web Cookie/Token Sessions and Authentication
Add Session Support to Flutter with Flutter Session
The mirror feature in Charles Proxy saves the responses -- I want to see the requests that are made for the corresponding saved response outside of the Charles UI so that I can programmatically match some of the data in the request to the response.
For instance, I might have a request to mysite.com/data?param=123 that results in the file data with the response value {"param": 123}. Then I might have another request mysite.com/data?param=456 and the same file data with a different response value.
I want to match the original request to the saved response.
You can use the Auto Save feature of Charles.
In "Charles - Tools - Auto Save", enable this feature and take "Save type" as "JSON Session File":
Then, all requests and corresponding responses will be saved as JSON data, which is pretty good for programming.
Does Syncfusion Dashboard web data source support POST http methods?
If yes, so how set it up?
Thanks!
HTTP Post requests additional data from client to server in the message body, where message body will be like JSON, XML, TEXT etc. This may result in the creation of a new resource or the updates of existing resources or both. In contrast, HTTP Get requests include all required data in the URL. So we support HTTP Get method since POST method is not valid use case.
Regards,
Umapathy S.
I am designing a RESTful API when I noticed something strange.
When I make a POST request for creating a new record, the form data is sent in request payload.
But when I make a PUT request to update a record, it appends form data in the URL, very similar to GET request.
Now a URL has certain length limit. So what would happen if PUT request has larger data than this limit.
Will the PUT request fail?
Is it unsafe to use PUT instead of POST to update a record having large form data?
EDIT:
I am using NodeJS server. I am using restangular(angular framework) to build my PUT request.
Use customPUT to send the form data in payload.
baseObj.customPUT(newObj).then(function(xyz){})
Have a look at these threads
Can HTTP PUT request have application/x-www-form-urlencoded as the Content-Type?
PHP multipart form data PUT request?
application/x-www-form-urlencoded or multipart/form-data?
Sounds like you can basically set a Content-type: multipart/form-data header and be golden. Basically comes down to configuration of the request with restangular and support thereof on the NodeJS server.
I use fiddler core to intercept the request and provide a response to it. I know its possible to use saz files to save the response. But the problem is that I need to be able to customize the response. While its a saz file I cant customize the response manually.
Is there a way to save response caught by fiddler to a text file in json like format, so that I could edit it and could serve it as response to any request using fiddler core? For now i see I can save response as a plain text. But how do I load this request to fiddler or parse it with fiddler core to populate all the response properties? Is there some format I could use, that will allow me to manually edit the response?
UPDATE
I see I can just open saz archive, make my edits to reponse and use it to specify the response. Thats exactly what I was looking for. Also there is a way to save response session as har file. Is it possible to save one single response as har/saz file? Currently I can only save session and it contain all requests and responses. Is there a way to limit saved data to 1 request and 1 response?
You have a SAZ file, which contains the full content of a response. Your code may load the SAZ File into FiddlerCore using the Utilities.ReadSessionArchive method. You will then have an array of Session objects.
As FiddlerCore receives requests, you can evaluate whether or not you wish to reply to each request using a previously-loaded response or whether you want to instead let the request flow through to the server. To let the request flow through to the server, do nothing.
To return a previously-generated response, in FiddlerCore 2.4.6.4+ (not yet released), simply call utilAssignResponse on the new Session. For earlier versions of FiddlerCore without this new method, your OnBeforeRequest method should call a method that looks something like this:
public void utilAssignResponse(Session oS, HTTPResponseHeaders oRH, byte[] arrBody)
oS.utilCreateResponseAndBypassServer();
oS.oResponse.headers = (HTTPResponseHeaders)oRH.Clone();
oS.responseBodyBytes = arrBody ?? Utilities.emptyByteArray;
oS.oFlags["x-Fiddler-Generated"] = "Generated by myCode";
}