I’m trying to write a Java code that makes HTTP requests that would run on both Windows and Android.
I’m given to understand that for Windows, Apache’s HTTPComponents is used, and for Android Volley is used. But it appears neither work on the other platform.
Is there a library that works on both? Or a uniform API layer on one of them that based on the OS decides what to use?
I’m using VS Code for Windows and Android Studio for Android, both latest versions, if it is relevant.
Thanks in advance!
3
Answers
You can give a shot to Swagger Editor. It generates client code for languages, not for platforms. You need to prepare a yaml file then click "generate client" -> "java". After then, you need to implement downloaded client into your project as gradle project.
code generator: https://editor.swagger.io/
documentation: https://swagger.io/docs/open-source-tools/swagger-editor/
you can use the Ktor client
but it requires Kotlin language
You can use Retrofit. According to the official website, Retrofit is a type-safe HTTP client for Java and Android which was developed by Square. With Retrofit, all you need to do is declare a Java interface to represent your API. Then, you can pass the API configuration to Retrofit, and you will get back a Java class implementation of your interface.