Skip to content

aatarasoff/thrift-api-gateway-core

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

17 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Thrift API Gateway Core

Join the chat at https://gitter.im/aatarasoff/thrift-api-gateway-core Build Status

Sometimes you need to do gateway for your API. This project provides core functionality for this.

What it is about

Imagine that you have a thrift service like this:

service InternalTestService {
    SomeReturnData getSomeData(
        1: UserData userData,
        2: RequestData requestData
    ) throws (1: SomeException e);
}

So, you have some user data that identifies him, for example id. But external client (mobile, web, other service) has only authentication token. And you want to build gateway that would be proxy request and translate message into your internal service.

So, you need to publish to client other service:

service ExternalTestService {
    SomeReturnData getSomeData(
        1: AuthToken authData,
        2: RequestData requestData
    ) throws (1: SomeException e, 99: UnauthorizedException ue);
}

As you see, difference beetween two services in the first argument and unauthorized exception as 99 field (I hope nobody needs more than 98 exceptions :) ).

MessageTranslator can get thrift message from external service and transform it into internal service message.

How to connect the project

Its very simple:

repositories {
    jcenter()
}
compile 'ru.aatarasoff.thrift:api-gateway-core:0.2.1'

How to use this

You need to create MessageTransalator and call process method. Also you need implement AuthTokenExchanger interface.

Message Translator is not thread safe. Remember that. If you have an exception while method process is called, you can process it with processError method.

See tests for better understanding.

Enjoy!

About

Core part for building API Gateway for Apache Thrift

Resources

License

Stars

Watchers

Forks

Packages