All Projects → envimate → httpmate

envimate / httpmate

Licence: Apache-2.0 License
Non-invasive, flexible and ultra-extendable http framework that offers you 3 modes of handling http requests - UseCase driven, low-level http and event-driven request handling, as well as a mix of those modes

Programming Languages

java
68154 projects - #9 most used programming language

Projects that are alternatives of or similar to httpmate

Ngx Restangular
Restangular for Angular 2 and higher versions
Stars: ✭ 787 (+5146.67%)
Mutual labels:  request, response, restful-api
chronosjs
JS Channels (Events / Commands / Reqest-Response / Courier) Mechanism
Stars: ✭ 35 (+133.33%)
Mutual labels:  request, response
buchu
Use Cases - Uniform, auditable and secure use case library
Stars: ✭ 23 (+53.33%)
Mutual labels:  ddd, usecase
active endpoint
[ARCHIVE] 🔧 ActiveEndpoint is middleware for Rails application that collect and analize request and response per request for route endpoint. It works with minimum affecting to application response time.
Stars: ✭ 13 (-13.33%)
Mutual labels:  request, response
Digital Restaurant
DDD. Event sourcing. CQRS. REST. Modular. Microservices. Kotlin. Spring. Axon platform. Apache Kafka. RabbitMQ
Stars: ✭ 222 (+1380%)
Mutual labels:  ddd, restful-api
Restairline
DDD+CQRS+EventSourcing+Hypermedia API+ASP.NET Core 3.1+Masstransit+terraform+docker+k8s
Stars: ✭ 243 (+1520%)
Mutual labels:  ddd, restful-api
WaterPipe
URL routing framework, requests/responses handler, and HTTP client for PHP
Stars: ✭ 24 (+60%)
Mutual labels:  request, response
Netclient Ios
Versatile HTTP Networking in Swift
Stars: ✭ 117 (+680%)
Mutual labels:  request, response
HttpUtility
HttpUtility is an open source MIT license project which is helpful in making HTTP requests and returns a decoded object from server. Right now this utility only parses JSON.
Stars: ✭ 28 (+86.67%)
Mutual labels:  request, response
Rhythm-CB-Scripts
Collection of scripts for use with Carbon Black Cb Response API
Stars: ✭ 14 (-6.67%)
Mutual labels:  response, restful-api
net
A small, modern, PSR-7 compatible PSR-17 and PSR-18 network library for PHP, inspired by Go's net package.
Stars: ✭ 16 (+6.67%)
Mutual labels:  request, response
Raypi
一个基于.NET Core 3.1的DDD(领域驱动)的极简风WebApi开发框架。
Stars: ✭ 138 (+820%)
Mutual labels:  ddd, restful-api
Examples
Examples of Mock Service Worker usage with various frameworks and libraries.
Stars: ✭ 163 (+986.67%)
Mutual labels:  request, response
reqres
Powerful classes for http requests and responses
Stars: ✭ 36 (+140%)
Mutual labels:  request, response
Holen
Declarative fetch for React
Stars: ✭ 152 (+913.33%)
Mutual labels:  request, response
Jonty.Blog
🎯Jonty.Blog个人博客项目,底层基于免费开源跨平台的.NET Core 3.1开发,使用 ABP vNext搭建项目框架,支持主流数据库,遵循RESTful接口规范,前端使用Blazor开发。
Stars: ✭ 42 (+180%)
Mutual labels:  ddd, restful-api
Plastic
This project provides encapsulation of things like Domain, Application Rules, Business Rules or Business Logic in Application.
Stars: ✭ 30 (+100%)
Mutual labels:  ddd, usecase
Kitura Net
Kitura networking
Stars: ✭ 98 (+553.33%)
Mutual labels:  request, response
Alamofire
Elegant HTTP Networking in Swift
Stars: ✭ 36,896 (+245873.33%)
Mutual labels:  request, response
izzyparser-ios
IzzyParser is an iOS library for serializing and deserializing JSON:API objects
Stars: ✭ 19 (+26.67%)
Mutual labels:  request, response

Maven Central CII Best Practices

HttpMate

HttpMate is an http framework that allows you to "just publish my business logic as HTTP endpoint". It's non-invasive, flexible and ultra-extendable.






Let's see some low-level example:

final HttpMate httpMate = HttpMate.anHttpMate()
        .get("/api/hello", new HttpHandler() {
            @Override
            public void handle(final HttpRequest request, final HttpResponse httpResponse) {
                httpResponse.setBody("Hello World!");
                httpResponse.setStatus(200);
            }
        })
        .build();

Treat the HttpMate instance as a description of your endpoints: we have here a request handler, for the path api/hello, with the request method GET, which handles the request by setting the response to the String Hello World! and the status to 200. Pretty descriptive, right?

This way of saying hello gives you full control over the HTTP protocol. Once your UseCase is more complicated than just saying hello, you want to focus on implementing it instead of dealing with protocol details.

Let's say we have a UseCase of sending an email:

public class SendEmail {
    private final EmailService emailService;

    //    @Inject if you so wish
    public SendEmail(final EmailService emailService) {
        this.emailService = emailService;
    }

    public Receipt sendEmail(final Email email) {
        final String trackingId = emailService.send(email.sender, email.receiver, email.subject, email.body);
        final String timestamp = String.valueOf(Instant.now().toEpochMilli());

        return new Receipt(trackingId, timestamp);
    }
}

Now we can expose this UseCase using HttpMate:

final HttpMate useCaseDrivenHttpMate = HttpMate.anHttpMate()
        .post("/api/sendEmail", SendEmail.class)
        .configured(toUseMapMate(MAP_MATE))
        .configured(toCreateUseCaseInstancesUsing(INJECTOR::getInstance))
        .build();

Want to extract the sender from the authorization, the receiver and subject from path and the email contents from the request body?

final HttpMate useCaseDrivenHttpMate = HttpMate.anHttpMate()
        .post("/api/sendEmail/<receiver>/<subject>", SendEmail.class)
        .configured(toUseMapMate(MAP_MATE))
        .configured(toCreateUseCaseInstancesUsing(INJECTOR::getInstance))
        .configured(toEnrichTheIntermediateMapWithAllPathParameters())
        .configured(toAuthenticateRequestsUsing(request -> {
            final Optional<String> jwtToken = request.headers().getHeader("Authorization");
            final Optional<String> userEmail = TOKEN_SERVICE.decrypt(jwtToken);
            return userEmail; 
        }).afterBodyProcessing())
        .configured(toEnrichTheIntermediateMapUsing((map, request) -> {
            final Optional<String> userEmail = request.authenticationInformationAs(String.class);
            userEmail.ifPresent(email -> {
                map.put("sender", email);
            });
        }))
        .build();

Want to use the very same UseCase to handle SendEmail events coming from an SNS topic? Refer to the "Event Driven HttpMate" (TODO) part of the README to see what modifications should be done to the httpMate object to achieve that.

What is HttpMate doing for you?

A good architecture is less about the decisions you make and more about the decisions you defer making.

HttpMate allows you to write your UseCases decoupled from the underlying hazards of an Http/Rest infrastructure.

Debating questions like:

  • "Should it be a PUT or a POST?"
  • "Is the Username coming from the request body, the JWT token or a plain text header value?"
  • "Are we talking JSON, YAML, XML or a custom (binary?) ContentType?"

is tiresome because you can't possibly know the answer until you've faced the customer. Furthermore, he might just change his mind.

And that's what HttMate is doing for you.

Other Features

Besides providing you with the described interface to build http request handlers, expose UseCases or handle events, HttpMate offers following features:

  • Several endpoint integrations such as - AWS Lambda - Jetty - Spark - Servlet
  • Integration with (de)serialization framework MapMate
  • Websockets
  • Predefined CORS configurations
  • Predefined MultiPart support

Why another HTTP framework?

The goal of refactoring is to actively counteract the natural increase in the degree of chaos

We did not find any framework that would allow us to develop a web application and claim in good conscience that its business logic does not depend on the underlying HTTP server, persistence layer or (de)serialization mechanism (also referred to as "infrastructure code" in DDD).

Getting started

Add the dependency:

<dependency>
    <groupId>com.envimate.httpmate</groupId>
    <artifactId>core</artifactId>
    <version>${httmate.version}</version>
</dependency>

Configure HttpMate with an HttpHandler and expose as a PureJavaEndpoint

public class Application {
    public static void main(String[] args) {
        final HttpMate httpMate = HttpMate.anHttpMate()
                .get("/api/hello", new HttpHandler() {
                    @Override
                    public void handle(final HttpRequest request, final HttpResponse httpResponse) {
                        httpResponse.setBody("Hello World!");
                        httpResponse.setStatus(200);
                    }
                })
                .build();

        PureJavaEndpoint.pureJavaEndpointFor(httpMate).listeningOnThePort(1337);
    }
}

Run the example and try

    curl http://localhost:1337/api/hello

Changing the endpoint

Since HttpMate separates the how is from the what, you can focus on defining what your http endpoints should do and decide on how to serve them best separately, based on the requirements of your infrastructure.

To expose the same httpMate instance using a Jetty endpoint, include the following dependency:

<dependency>
    <groupId>com.envimate.httpmate.integrations</groupId>
    <artifactId>httpmate-jetty</artifactId>
    <version>${httpmate.version}</version>
</dependency>

And replace the PureJavaEndpoint line with:

    JettyEndpoint.jettyEndpointFor(httpMate).listeningOnThePort(1337);

Restart the application and enjoy the benefits of Jetty.

Documentation

You can find an extensive documentation here.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].