JKFramework Service Client

Service client is a project that aims to simplify Microservices and REST-API clients development.

It consists of two clients clients:

  • Simple Client that communicates with traditional microservices.

  • Mature Service Client that communicates with Mature Microservices.

Mature Microservice is a maciroservice that uses HTTP protocol methods instead of API specific URL as a common protocol between servers and clients.


Most likely, you will NOT need to add the direct dependency of this project, since its already included in the parent projects or the other framework projects. However, if you need to, the dependency is

<!-- https://mvnrepository.com/artifact/com.jalalkiswani/jk-framework-core -->

Basic Usage

  1. Create Maven Project with JK-App-Data as the Parent.

  2. Create and use of the following clients per your needs.

Traditional Service Client

To use it, declare ServiceClient instance with the API URL base and the common Model as parameters, then use that instance to call a the method of your need. for example:

String url = "http://localhost:8080/app/example";
JKServiceClient<Person> client = new JKServiceClient<>(url, Person.class);

String response = client.callJsonAsString("/hello");

String response2 = client.callJsonAsString("/hello/Jalal");

Person p = new Person();

String response3 = client.callJsonWithPost("/hello", p);

The recommended approach is to:

  1. Create a service client with the name of your microservice

  2. It should extends the ServiceClient

  3. Override the getBase() method, and load the URL from the configuration.

  4. Provide a bushiness wrapper methods to all the end points in the Microservice.

Here is a full example:

package com.app;

import com.jk.core.config.JKConfig;
import com.jk.services.client.JKServiceClient;

public class DemoSeviceClient extends JKServiceClient<Person> {

	public String getBase() {
		return JKConfig.get().getProperty("example.service.url", "http://localhost:8080/app/example");

	public String hello() {
		return callJsonAsString("/hello");

	public String hellowithParam(String name) {
		return callJsonAsString("/hello/" + name);

	public String helloWithModel(Person p) {
		return callJsonWithPost("/hello", p);


and you use it with some thing like this:

DemoSeviceClient client=new DemoSeviceClient();

The service client and the needed models should be created by the Microservice developer him/her self, and place it in a commons-lib that is accessible by all projects, in this approach, any new update to the client will be immediately available to all apps.

If you need to cast the response (which normally is a json object), you can use one of the following utility methods:

  • JKObjectUtil.jsonToObject(json, Class)

  • JKObjectUtil.jsonToObjectList(json,Class

Mature Service Client

Mature Service clients is a client that is designed to communicate with Mature MicroService. As explained, mature microservice uses the standard HTTP methods as the standard application protocol between an API and its client.

To use this client, you need to:

  • Class a client of your service that extends JKMatureServiceClient

  • Provide your model as Generic parameter.

  • Override getBase method.


package com.app.person;

import com.jk.core.config.JKConfig;
import com.jk.services.client.JKMatureServiceClient;

public class ExampleServiceClient extends JKMatureServiceClient<Model> {

	public String getBase() {
		return JKConfig.get().getProperty("example.service.url", "http://localhost:8080/app/example");


This client provide the following methods out of the box:

  • getAll() which calls GET method

  • find(id) which calls GET method with query param;

  • insert(model) which call POST method

  • update(model) which calls PUT method

  • delete(id) which calls DELETE method. -