How can we handle api response in both platform in ios and android in kotlin mutlplatform? - swift

Hey I am new in the world of Kotlin Multiplatform mobile. I have experience in development of android field. I am trying to connect Android application and Ios application. I searched and see Ktor is the way to fetch data from server. In android we use Kotlin Sealed Classes for Handling API Responses example in your application and in ios side team use Understanding Swift closures and asynchronous request functions similar to these. I am little bit confused, How can I use this way in common module to use both platform because both platform have Interceptor and many more things. Do I need to write everything from scratch? or Is there any way we can use existing way. My both platforms application is huge project. I don't won't to replace the code. I want to start new api call throught KMM using Ktor. Any suggestion or project would be helpful for me. Thanks

You don't need to write anything from scratch. Basically you will need a separate Network Layer which will be in shared module. It will mainly consists of your request/response models and api call stuff. Here only you can define a sealed class which will provide you if the api is success or failure in your api callback and based on that you can handle your response.
You can refer to this amazing sample for your usecase. You can also refer to this blog for in depth understanding.

If you want to use old Android Code into Kotlin-Multiplatofrm Project you need to do some steps
First Step : you should separate your code into business layer and presentation layer you can know about it by reading clean architecture Android
Second Step : we will put business layer into Shared Module then we will put presentation layer into ANDROID APP
Third Step : you should replace Retrofit Code with Ktor Code
Fourth Step : You should replace Room Code with SqlDlight Code
fifth Step : You Should Write your view in presentation layer with Compose not Xml
then application will be ready to use his business logic into ios
sixth Step : then you can write your swift code into IOS APP
you can look at this code this is not complete code but it will make it clear to you haw you can use
my Kmm Repo at Github
note :
Presentation layer contain view , viewmodel and any Platform dependent tools like workmanger
business layer contain network and caching code like KTOR , SQLDELIGHT and any logic that may be shared between Android and Ios

Related

In Zoom’s Web SDK, is Zoom.generateSignature development only?

I’m looking to implement the Zoom Web SDK into my React apps and wondering what’s the correct way to generate a signature.
From some examples, I see that it should be a new endpoint to generate one.
However when looking at this example, it seems like ZoomMtg exposes a generateSignature method. It does say to use this in development only, but I’m just wondering what would be the correct way to implement this. Should it be a separate service? Or could I rely on this to generate a signature on a production app?

Rest API and admin in the same application

I'm new to building APIs, I made the first one using an MVC framework: codeigniter, with chris kacerguis rest implementation.
I'm not really sure this was the best think to do because I believe maybe the framework is not that "slim" or light just to API's purposes.
I plan to do a mobile App, an admin and a website so the three can consume the Api's services.
Is it a bad idea to have the API, the website and the admin on the same project? which are the pros and cons? or the best architectural approach?
Otherwise I will have: One Codeigniter project for the API and Another Codeigniter project for website and admin
thanks
You can create folders in "controllers" folder to organize your project and use the same project/env configuration :
controllers/Home.php
controllers/api/MyApi.php
controllers/admin/Admin.php
Edit : You will share models and libraries too.
In my project I realized 2 types of controller - REST and API. Admin js gui work with REST, other world work with API. You can do it simply with silex framework, a little brother of symfony.
The purpose of building a REST API so that you only have to build one project for your business model. This allows you to construct any number of applications on any platform, only requiring you to consume the API in different ways. This essentially separates/decouples the user interface from the business logic, and vice versa.
You should create separate projects for the REST API and each UI project should also be separated projects. This allows you to change the underlying code, language and platform in any one of the projects without breaking any of the other projects as long as the API signatures remain the same.
For example, you could have a live version of your website built using Codeignitor while developing another septate project using AngularJS. When your AngularJS project is complete you would simply swap out the project on your server (or create an entirely new website or server) still allowing you to use the other if required. Additionally, you may decide that you would like to move the API onto a different platform, language or database, develope it and swap the implementation when finished causing no changes to any of your UI projects assuming you have not changed the API signatures.

A good way to structure AngularJS client code with Play 2.1 as backend

I own a Play 2.1 application.
Initially, I used the default template mechanisms from Play 2.1 until I .. learned AngularJS.
Now, I clearly want my client side to be an AngularJS app.
However, while surfing the net, I find there are no clear way to achieve it:
Letting Play behave as a simple RESTful application (deleting the view folder) and making a totally distinct project to build the view (AngularJS app initialized by grunt.js).
Advantage: Likely to be less messy, and front and backend teams would work easily separately.
Drawback: Need another HTTP server for the AngularJS app.
Try to totally integrate AngularJS app with the traditional Play's workflow.
Drawback: With a pretty complex framework like AngularJS, it would lead to a confusion of templates managementfor instance : scala.html (for Play) / tpl.html (for Angular) ... => messy.
Making a custom folder within the play project but distinct from the initial folders created by the Play scaffolding. Let's call it myangularview instead of traditional view for instance. Then, publish static contents generated by grunt.js into the Play's public folder, in order to be reachable from browser through Play's routing.
Advantage: SRP between components is still fairly respected and no need to use another light HTTP server for the client-side like in 1.
I pointed out my own views of advantage and drawbacks.
What would be a great way to achieve the combination of Play with Angular?
Yes, I'm answering to my own question :)
I came across this way of doing:
http://jeff.konowit.ch/posts/yeoman-rails-angular/
Rails?? No matter the framework is, the need remains exactly same.
It advocates a real separation between APIs (backend side), and front-end side (in this case making AJAX calls to backend server).
Thus, what I've learned is:
During development phase, a developer would use two servers: localhost on two distinct ports.
During production phase, the front-end elements would be encompassed into the whole backend side (the article would deal with a kind public folder, aiming to serve static contents: HTML, angular templates (for instance), CSS etc... Advantage? => dealing with a one and unique serving server's APIs exposition as well as static assets for the UI.
With this organization, some tools like Yeoman would be able to bring some really awesome handy things to developers like for instance: the livereload feature. :):)
Of course, during development phase, we end up with two different domains, (localhost:3000 and localhost:9000 for instance) causing issues for traditional ajax requests. Then, as the article points out, a proxy may be really useful.
I really find this whole practice very elegant and pleasant to work with.
There was an interesting discussion on the play mailinglist a couple of days ago about frontend-stack/solution, could be something in it for you, quite some people using angular it seems: https://groups.google.com/forum/#!searchin/play-framework/frontend/play-framework/IKdOowvRH0s/tQsD9zp--5oJ

Implement LRS With Tin Can API for iPhone

I have to create a project in iPhone which uses the Tin Can API. The Tin Can API is an advanced distributed learning process.
I have no idea about where to start in Objective-C.
I have read the site http://tincanapi.com.
For implementation, I have some basic questions:
How and to create my own LRS?
How Tin Can API can communicate with my own LRS and LMS with ASIHTTPRequest programatically?
There are two parts to TinCanAPI at play here. I'm suspecting you only need to handle one of them on iPhone. One part is the client-side that sends the statement date to the second part (the LRS server-side). It would be very odd to create the LRS server part on an iOS device, so I'm going with the thought that you need to send TinCan statements from an iOS device to an existing LRS.
An LRS accepts statement data via a REST interface and this data can be POSTed using a standard NSURLConnection or using AFNetworking. There are a couple of options for abstracting all those calls with a library one of which is a new OSS version of the basics appearing very soon from Rustici Software found here http://rusticisoftware.github.io/TinCanObjC/. There is no link for it just yet, but feel free to contact me for more details and I'll update this answer with the link as soon as there is a public link.
For your specific questions:
1.) You can create your own LRS by understanding the spec document and creating the REST endpoints as specified. This is not a trivial undertaking by any means.
2.) Your best bet is to use an SDK or simple GET and PUT/POST statements from AFNetworking to the TCAPI endpoint.

Architecture Question: GWT or Vaadin to create Desktop Application?

We're planning on creating a feedreader as a windows desktop- and iPad application. As we want to be able to show Websites AND to run (our own) JavaScript in this application, we thought about delivering the application as HTML/CSS/JavaScript, just wrapped by some .NET control or a Cocoa Touch webbrowser component. So the task at hand is to find out which framework to use to create the HTML/CSS/JS files to embed in the application.
For the development of the HTML/CSS/JavaScript we would be happy to use Vaadin, GWT, or some other framework, as we're a lot better with Java than with JS. We favor Vaadin after a short brainstorming, as the UI components are very nice, but I fear that most of the heavy lifting will be on the server and not in the client (and that wouldn't be too nice). We would also like GWT, but the Java-to-JS compiling takes a lot of time and an extra step, and slowed down development time in the past when using it.
The question is: which development framework would you choose (given you wanted to implement this project and you mostly did Java so far) and why? If there are better framework options (List of Rich Client Frameworks), please let me know.
Edit: The application will need to talk to our server from time to time (sync what has been read for example), but mainly should get the xml feeds itself. Therefore I hope that most of the generated code can be embedded in the application and there doesn't need to be heavy activity with our server.
Edit2: We (realistically even if you doubt) expect at least 10000 users.
Based on my experience with Vaadin, I'd go for that, but your requirements are somewhat favoring pure-GWT instead.
Vaadin needs the server and server connection. If building mostly offline desktop application, this can be solved with an embedded Jetty for example. (synchronize with an online service only when needed), but for iPad you would need to connect online right away to start the Vaadin application.
GWT runs completely at the client-side and you can build a JavaScript browser application that only connects when needed.
Because Vaadin is much quicker to develop, you could build a small Vaadin version first and see if that is actually problem on the iPad.
On the other hand, if you can assume going online right away, you can skip the local server installation altogether. Just run the application online and implement the desktop version using operating systems default browser control (i.e. the .NET control you suggested). Then Vaadin is easier.
Vaadin is just framework base on GWT but have two very important features:
don't need to run GWT compiler. It is pure java. Of course if not add addons because then gwt compiler must run.
you don't need to write communication code. So you don't need to solve DTO problems, non-serializable object mappings and dont need to write servlets.
I use Vaadin in my work for one year and we haven't performance problems yet (desktop like application with ~500 users). IMO very good solution is to use Vaadin just for UI, logic move to independent beans and connect this two elements using Spring or Guice.
In this case you should use MVP pattern and Domain Driven Development.
Bussines beans is domain objects and logic that use view interfaces to send responses.
Custom Vaadin components (could extends standard components) implements view interfaces.
That way is good when you decide to change UI engine if Vaadin is not for you. Just rewrite guice/spring mappings and write new implementations of view interfaces.
My 3 cents:
If you decide to use vaadin, You will benefit from already GOOD LOOKING components. Since you dont want to write (alot of) CSS , vaadin is already good looking out of the box. How ever, Vaadin is a SERVERSIDE framework. User interface interactions will hit the back end even if they dont involve getting any data (e.g moving from one tab to the other) .
If you decide to use GWT, you will have to atleast style the application (this is not hard) . There is also the problem of long compilation time (but you can test and debug on hosted mode which allows you to run the application without compiling , then you compile only when deploying). The main advantage of gwt is that you control what gets sent to the wire, For UI interactions that dont require getting data from the backend, it will work purely on the client side. You the developer will determine when to send a request to the back end. (Doing RPC requests in GWT is very easy)
Hope this will help you make the decision.