http requests with Kotlin multiplatform for desktop - kotlin

I'm new to kotlin multiplatform and I'm using compose for desktop, how can I make HTTP requests?
is there any resources to learn from?

Ktor is the best supported multiplatform HTTP client currently, as it is maintained by Jetbrains There are also projects that put together many open source tools for kotlin multiplatform such as: AAkira
There is not a specific place currently that goes over HTTP communication, as it would be specific per tool you choose.

Related

Does exist a universal tool to describe different APIs (REST, WebSocket, gRPC, custom framework)?

My project uses different protocols to communicate with other services:
REST API
WebSocket (STOMP)
gRPC
own framework build over gRPC.
I need a tool, or a bunch of tools, which allow me to generate documentation for the APIs. In the best scenario, it's a maven plugin that generates a report with all APIs.
We use Swagger to describe the REST API. It has poor export options and needs a lot of annotations in the code, but describes the API well and offer the test machine.
Alternatively, Spring RestDocs (AsciiDoctor) could be used for the REST API describing. It offers a better format for reporting, but we prefer Swagger.
That's all I found for the REST API. But I didn't find anything for describing WebSocket API, gRPC and the custom framework.
I will be very grateful for any help and ideas to solve the problem.

Websocket client in Kotlin

I was wondering why there is no Websocket client native object in Kotlin like it is in javascript.
How does one connect to a Websocket server in kotlin as I created a Node.js websocket server and want to connect to it using an Android client.
Can someone please elaborate on this.
Thanks.
There is. If your question is about Kotlin native/multiplatform, you can use ktor client:
https://ktor.io/clients/websockets.html.
On the Android side, you would need to use CIO or OKHttp engines. On the javascript side, Js engine. On the iOS side, there is currently no support available out of the box, but it's supposed to be coming soon.
If your question is not about Kotlin native/multiplaform, you can still use the above or org.java_websocket.client.WebSocketClient, or any of the third party libs.

How to use kotlin as a server side lanaguage?

I want to develop server side application like a blog app, So how can i use kotlin programming language as a server side language.
Ktor is a framework for building asynchronous servers and clients in connected systems using the powerful Kotlin programming language. This website provides a complete reference to the Ktor application structure and programming interface. And how to approach particular tasks.
Ktor offcial site

Using a JSON-API server library in a Ktor application

I have a Ktor application (in Kotlin) and would like the endpoints to be exposed according to the JSON:API specification. I understand my library options are between the Java server libraries for JSON:API, i.e. Katharsis (which gives code examples for Dropwizard, Spring Boot etc.) and Crnk (which gives example for Spring Boot). I have tried a bit with Katharsis but it's not clear to me how the ResourceRepositoryV2 class should be registered/exposed by the Ktor application.
Any examples or pointers?

Does api work like bytcode to provide multi-platform functionality

I've recently come across the term api and from what I have known api is a interface that connects/integrates between two programs and it can run on any platform.
And again from java we know that it turns it's source code into bytecodes and this bytecode can run on any platforms since it is platform independent.
So my question is does api work/run just like as a bytecode to provide multi-platform functionality
And if not is there any similarities between them or thier process? If please anyone could explain it to me it would be a great help. Thanks in advance.
API does not work like bytecode
Actually, API and Bytecodes are a completely different thing
For Bytecode,
let's try to understand it in java. java compiler compiles a java program then produce bytecode. Then the bytecode is interpreted by java interpreter in different machines and generate different executable files as the requirement of different machines and os.
this is how java maintains it's multi-platform property
Now, API,
API stands for Application Programming Interface. An API is a software intermediary that allows two applications to talk to each other. In other words, an API is the messenger that delivers your request to the provider that you’re requesting it from and then delivers the response back to you.
there are many types of API's out there
but I think you are referring to Web API and it's multi-platform functionality and how it works.
A Web API is an application programming interface for either a web server or a web browser
A Web API works as server-client architecture.
client request to server through HTTP protocol, server responds to client through HTTP protocol
actually whole api service is provided through HTTP protocol, and this api service can provide to any device using HTTP protocol
this has nothing to do with bytecode