How to debug API response using MVVM Android Architecture - mvvm

I was trying to fetch data from a remote API, following MVVM and Google Architecture Pattern with:
LiveData
Retrofit 2
Dagger 2
Observable
Databinding
My question is:
How can I debug the Api response?
In my last project (using Asynctask, retrofit and GSON) I can stop in the moment when the Api response, so I could see the header of the response if it was a 200 response or 404. Then I could see the json of the Api response, etc...
Using this repo I can't see anything of what I said above, for example, I don't know if the data received was ok or if the model is filled with the JSON response.
I don't gonna copy and paste the code because I'm learning with the repo above and I think that my question is more theoretical.
Anybody has felt like me with this new pattern and architecture?
Anybody can help me solving my problem?
Thanks!

I think Stetho is the best tool for tracking API responses and DB changes.
First you have to init it in your Application class:
public class MyApplication extends Application {
public void onCreate() {
super.onCreate();
Stetho.initializeWithDefaults(this);
}
}
Then add it to your OkHttp client:
new OkHttpClient.Builder()
.addNetworkInterceptor(new StethoInterceptor())
.build();
Finally open Chrome, then type
chrome://inspect/#devices

Related

Configure flutter web app to broadcast data to any subscribed listeners with sse

I am currently developing a flutter web app, and would like to implement a feature to broadcast json data to any listeners/subscribers.
To give more detail:
The web app has a flutter front end server running on localhost. A user will be able to fetch some JSON data from an external backend server using a simple GET request.
Once the app has loaded the JSON data, it will need to broadcast it down an SSE stream to any listeners. This listener will be a seperate flutter application.
Now, I understand that there a few problems with this.
Firstly, Flutter web doesn't support dart:io... Fine - I have managed to get round this by using the universal_io dart package instead of dart:io. The api is the same, and after solving a few CORS errors, works a charm for the GET requests in the first bullet above. This means that the json data can be successfully loaded into the Flutter app.
(universal_io dart package -> https://pub.dev/packages/universal_io).
The next issue is with SSE. Part one of this is that there is not much documentation on implementing an SSE server in Flutter - only a client that can listen. However, I have managed to find a solution in the sse dart package example app...
import 'package:shelf/shelf_io.dart' as io;
import 'package:sse/server/sse_handler.dart';
/// A basic server which sets up an SSE handler.
///
/// When a client connnects it will send a simple message and print the
/// response.
void main() async {
var handler = SseHandler(Uri.parse('/sseHandler'));
await io.serve(handler.handler, 'localhost', 0);
var connections = handler.connections;
while (await connections.hasNext) {
var connection = await connections.next;
connection.sink.add('foo');
connection.stream.listen(print);
}
}
(sse dart package -> https://pub.dev/packages/sse)
(continued) Usually, this would be a fine solution, and it could probably be modified a little for implementation within a flutter app. However, the shelf_io.dart package, used to spin up the server, depends on the dart:io package, which doesn't work with Flutter Web.
The other thought is - why do we need to set up a new server connection (with io.server(...)) when the flutter web app is already running on its own localhost server? This begs the question: Is there a way to add this sseHandler endpoint onto the localhost server that the Flutter Web app is running on?
All in all, what i'm trying to ask is:
Is there a way for a Flutter Web App to send SSE messages to a collection of listeners?
At the moment I've hit a bit of a deadend with research on this so if anyone had any bright ideas on a potential solution then the help would be greatly appreciated. Thanks :)
Side Note: Obviously this is something that could very easily be done with Java, J2Html and so on, but wheres the fun in giving up just like that... On the other hand, maybe flutter web is still just too new to support stuff like this?

Sails.js override response methods

I'm using SailsJS 0.9.8 and I would like to add some information to each API response if the response should go to a websocket.
The reason I want to do this is that the application makes use of websockets a lot via socketIO and when using the send() and json() methods of the response object the status code is not added to the json that is sent to the socket which is otherwise available if sending via http. I could just add the status to the json before sending but it would get messy so I would like to do it some other way.
Some of the response methods, like badRequest() and serverError() etc, do add the expected status code but send() and json() do not, even if I give it as a parameter. Is it possible to change this behaviour?
P.S. I did look at this question which is basically the same as my question but the chosen answer didn't work for me, i copied the source files for badRequest and put it in api/responses/ and simply added a printout but it never showed.
Thanks
I know that this is supported in sails.js 0.10.x: http://sailsjs.org/#/documentation/concepts/Custom-Responses

Differences between a PortletRequest and a PortletResponse object

I understand that the Request objects (RenderRequest, ActionRequest, ...) contains the request we made, and the Response objects the response from the portlet...
But how, step by step everything works ?
If I take an example, I have a portlet with a little form. When I click onto the Send button, what is into the ActionRequest and the ActionResponse and when ? And after this first processing, what contains the RenderRequest and the RenderResponse objects?
Thanks for your help !
P.S: I don't use Spring MVC
I think the answer you seek is available in the JSR specs; either the old one (http://jcp.org/en/jsr/detail?id=168) or the new one (http://jcp.org/en/jsr/detail?id=286) depending on your environment.
The specs are free to download and give a fair overview of the concepts.

OpenRasta streaming response

Does anyone know if it is possible to write to the response stream in OpenRasta rather than returning an object as a response resource? Alternatively, am I able to implement an HTTP handler but still leverage OpenRasta's URL rewriting?
Thanks
Chris
You can always keep an http handler on the side to do specialized things, but that ties you to asp.net and will prevent your code from being portable on other hosts. If that's something you're ok with, any handler that's registered for a specific route will get executed before openrasta on asp.net.
that said, codecs are the ones writing to the response stream, so provided you have a custom IMediaTypeWriter you can write the resource instance on a stream whichever way you want.
Say for example that you returned an IEnumerable from your handler, as those get deferred executed, you can just start the enumeration of those in your custom codec without any problem.

AutoResponder in FiddleCore

is it possible to develop an AutoResponder like actions for FiddleCore?
in this question it said that we should wait for new version of Fiddler. it's out. what now?
Yes, you can write an AutoResponder-like feature using FiddlerCore. The FiddlerCore package includes a class that allows you to load a .SAZ traffic archive capture.
You can then play back the responses that you loaded by hooking the BeforeRequest method, and using the oSession.utilCreateResponseAndBypassServer() method.
You'd check the URL and/or other data to figure out which response to return, and copy the response data out of the loaded session into the new response.