Skip to content

hekonsek/rxjava-connector-http

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

26 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

RxJava HTTP connector

Version Build Coverage

Connector for RxJava bridging HTTP endpoint with RxJava events.

Installation

In order to start using Vert.x Pipes add the following dependency to your Maven project:

<dependency>
  <groupId>com.github.hekonsek</groupId>
  <artifactId>rxjava-connector-http</artifactId>
  <version>0.1</version>
</dependency>

Usage

This is how you can start embedded Vert.x-based HTTP server and consume incoming requests:

HttpSourceFactory httpSourceFactory = new HttpSourceFactory(vertx);
httpSourceFactory.build("/foo").build().subscribe(event ->
  System.out.println("POSTed JSON: " + event.payload())
);
httpSourceFactory.listen().subscribe();

If you would like to send a response back to the client, you need to obtain a response callback from the incoming request event:

import com.github.hekonsek.rxjava.connector.http.HttpSourceFactory;
import static com.github.hekonsek.rxjava.event.Headers.requiredReplyHandler;

...

HttpSourceFactory httpSourceFactory = new HttpSourceFactory(vertx);
httpSourceFactory.build("/foo").build().subscribe(event ->
  requiredReplyHandler(event).reply(ImmutableMap.of("hello", ""world));
);
httpSourceFactory.listen().subscribe();

By default response objects are automatically converted to JSON.

License

This project is distributed under Apache 2.0 license.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Packages

No packages published