GET, POST, PUT, DELETE
- Maven:
<repositories>
<repository>
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
</repositories>
<dependency>
<groupId>com.github.jkanTech</groupId>
<artifactId>goma</artifactId>
<version>1.0.3</version>
</dependency>
- JitPack.io, add
jitpack.io
repositiory and dependency to yourbuild.gradle
:
repositories {
maven {
url "https://jitpack.io"
}
}
dependencies {
implementation 'com.github.jkantech:goma:1.0.3'
}
repositories {
maven {
url "https://jitpack.io"
}
}
dependencies {
implementation 'com.github.jkantech:goma:1.0.3'
}
<uses-permission android:name="android.permission.INTERNET"/>
<application
android:usesCleartextTraffic="true"
private fun getUsers(){
// initialize Goma Library
Goma.init(this,"http://192.168.8.101/api/v1")
//GET Method ,path
Goma.get("users", object : OnResponseListener {
override fun onSuccess(response: String?) {
users=users.deserializer(response)
Toast.makeText(requireContext(), response.toString(), Toast.LENGTH_SHORT).show()
}
override fun onError(error: String?) {
Toast.makeText(requireContext(), error.toString(), Toast.LENGTH_SHORT).show()
}
})
}
private fun addUser(){
// initialize Goma Library + baseURL
Goma.init(this)
val parameters:HashMap<String, String> = HashMap()
parameters.put("appKey","12345#")
parameters.put("name","Jonas")
parameters.put("title","Inform")
parameters.put("age","18")
//POST Method ,path
Goma.post("http://192.168.8.101/api/v1/add",parameters, object : OnResponseListener {
override fun onSuccess(response: String?) {
Toast.makeText(requireContext(), "Successfully added", Toast.LENGTH_SHORT).show()
}
override fun onError(error: String?) {
Toast.makeText(requireContext(), error.toString(), Toast.LENGTH_SHORT).show()
}
})
}
private fun add(){
// initialize Goma Library
Goma.init(this)
val parameters: HashMap<String, String> = HashMap()
parameters["Appkey"] = "12345"
parameters["name"] = "Bob"
parameters["title"] = "Infor"
parameters["age"] = "30"
Goma.put("http://192.168.8.101/api/v1/adduser", parameters,object :OnResponseListener {
override fun onSuccess(response: String?) {
Toast.makeText(this, response.toString(), Toast.LENGTH_SHORT).show()
}
override fun onError(error: String?) {
Toast.makeText(this, response.toString(), Toast.LENGTH_SHORT).show()
}
})
}
private fun delUser(){
// initialize Goma Library
Goma.init(this)
val parameters:HashMap<String, String> = HashMap()
parameters.put("appKey","12345#")
parameters.put("id","4")
//DELETE Method ,URL
Goma.del("http://192.168.43.128/api/delUser",parameters, object : OnResponseListener {
override fun onSuccess(response: String?) {
Toast.makeText(requireContext(), "Successfully deleted", Toast.LENGTH_SHORT).show()
}
override fun onError(error: String?) {
Toast.makeText(requireContext(), error.toString(), Toast.LENGTH_SHORT).show()
}
})
}
Download the Goma Example App or look at the source code.
- Jonas Kaninda - jkanTech
This project is licensed under the Apache License 2.0 - see the LICENSE file for details.