Retrofit for Android - include dependencies between calls - retrofit

I do have different types of API calls, some of them depend on each other, i.e. they may only start after another one returns. Is there a way in Retrofit (2) to declare these type of dependency? I implemented my calls asynchronously.

Related

Call remote test library constructor as keyword from Robot Framework

Is it possible to call Test Library constructor from Robot Framework?
Using Remote library interface (NRobot.Server) to connect from RF to Test Library (implemented in C#).
Currently its exposing all public methods implemented under Test Library except constructors.
There are multiple Test Libraries in our project where some functionality implemented as part of constructors.
Hence need a way to call constructor as a test step to execute certain functionality whenever required.
If not possible then may need to move functionality from constructors to new public methods. But want to avoid that if possible.
Thanks in advance...
In short - no.
When calling a remote library, you're actually just the client in an XML-RPC comm protocol; it is the server's responsibility to have the library instantiated, so it (the very same library) can process your instructions and act as needed. Thus normally the library is already instantiated when you call it from your RF code - too late to invoke its constructor.
Naturally, this can be implemented differently - for the remote library server to instantiate the target library on a (special) call, and thus you'll to be able to provide constructor arguments, but that is library design/code change required in it.
This is in contrast of using local libraries, where they are instantiated in your local interpreter, on their import.

Can I mix Ktor with Exposed?

I am writing a service using Ktor and Exposed ORM which apparently isn't async. I am coming from the Python world and back there using a blocking ORM with a async IO library is a sin as it may block all users in thread.
Does the same rule apply in Kotlin? Am I creating a bad architecture?
Exposed uses thread local storage to keep transaction instance accessible to implementation and avoid passing it along with every function call. Since transaction DSL function is executing synchronously and do not release a thread to be reusable by ktor for other calls there shouldn't be any issues with using them together.
There is coroutine support in Exposed.
Please read the documentation:
https://github.com/JetBrains/Exposed/wiki/Transactions#working-with-coroutines
Here's a blogpost that shows how to use them together:
https://ryanharrison.co.uk/2018/04/14/kotlin-ktor-exposed-starter.html
I have also successfully done so myself in a test-project but I'm not yet at a point where I'm ready to share the code.
In short, you can use Kotlin coroutines in such a way that you do the database transaction on a thread so they do not block KTOR's request handling loop.
If using the right coroutine dispatcher, then this should not give any problem with the threadlocal transaction context.

how to avoid compile time dependency to a rebus message?

I want to integrate two bounded contexts via events raised by Context A and consume the Events from Context B.
How ever i want to avoid compile time dependency, so Context B does not have to include dll's/libraries of Context A. (At least i don't want the hassle of needing to update a reference to A every time a new Event type gets exposed by Context A.
Is there any prefered/best practice to do this with Rebus?
There's a couple of ways, actually :)
Myself, I prefer to distribute the messages as separate NuGet packages – then it becomes a matter of looking into packages.config to see which dependencies each endpoint has.
As long as I keep published message schemas immutable (i.e. follow a strict append-only approach to evolving it), there's no problem in consuming events – the data is simply truncated when deserializing into an old version of the message schema.
But if you want your endpoints to be less coupled than that, you can do a couple of things.
Unless you change the serializer, the messages are serialized as UTF8-encoded JSON. This means that a subscriber can always install its own JSON serializer, that could e.g. deserialize the message to its own types, or simply into a JObject (assuming you are using Newtonsoft JSON.NET).
In fact – if I recall correctly – you can include the NuGet package Rebus.NewtonsoftJson and use it by going
Configure.With(new CastleWindsorContainerAdapter(container))
.(...)
.Serialization(s => s.UseNewtonsoftJson())
.Start();
which brings with it Newtonsoft's JObject into the mix, which you can then use in your message handler by implementing IHandleMessages<JObject>.
I hope that gives you some inspiration :)

Is retrofit of any use if I am already using okhttp3, Moshi and Rxjava in my project?

I have done some R&D on above libraries and have used some in my project.I am using Moshi for json parsing, OkHttp3 library for http connections and Rxjava for asynchronous and event based programming in my project. Now when I looked at retrofit, I felt its of no use as I have already used above main components of retrofit myself.
Just want to know the ideas of the people whether I am thinking in right direction or not.
Edit: From my point of view, Retrofit only provides clean interface of http client where one can customize requests,headers etc with annotations.
This is a good choice of libraries from my point of view. The first three are developed by Square and they work very well together. However the main difference is that each library works on a different layer.
OkHttp: transport layer. Deals with http protocol. Performs networking.
Moshi: Json parser. Transforms bytes from OkHttp into a Java objects.
Retrofit: Rest layer. Transforms HTTP logic (status codes), into REST logic.
RxJava: provides tools to create reactive code, instead of imperative code.

node.js asynchronous initialization issue

I am creating a node.js module which communicates with a program through XML-RPC. The API for this program changed recently after a certain version. For this reason, when a client is created (createClient) I want to ask the program its version (through XML-RPC) and base my API definitions on that.
The problem with this is that, because I do the above asynchronously, there exists a possibility that the work has not finished before the client is actually used. In other words:
var client = program.createClient();
client.doSomething();
doSomething() will fail because the API definitions have not been set, I imagine because HTTP XML-RPC response has not returned from the program.
What are some ways to remedy this? I want to be able to have a variable named client and work with that, as later I will be calling methods on it to get information (which will be returned via a callback).
Set it up this way:
program.createClient(function (client) {
client.doSomething()
})
Any time there is IO, it must be async. Another approach to this would be with a promise/future/coroutine type thing, but imo, just learning to love the callback is best :)

Resources