Skip to content

Commit

Permalink
Merge branch 'development'
Browse files Browse the repository at this point in the history
  • Loading branch information
noboomu committed Mar 28, 2019
2 parents d3dafb8 + 20cdfec commit 9e1eee1
Show file tree
Hide file tree
Showing 92 changed files with 6,339 additions and 5,377 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,4 @@ bin
.factorypath
.idea
.idea/*
*.iml
1 change: 0 additions & 1 deletion .idea/.name

This file was deleted.

90 changes: 71 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@

![Alt logo](https://raw.githubusercontent.com/noboomu/proteus/master/src/main/resources/io/sinistral/proteus/server/tools/swagger/proteus-logo.svg?sanitize=true)
![Alt logo](https://raw.githubusercontent.com/noboomu/proteus/master/core/src/main/resources/io/sinistral/proteus/proteus-logo.svg?sanitize=true)

An extremely __lightweight, flexible, and high performance__ [Undertow](http://undertow.io) based Java framework for developing RESTful web applications and microservices.
An extremely __lightweight, flexible, and high performance__ [Undertow](http://undertow.io) based Java framework for developing RESTful web applications and microservices

- __NO MAGIC__
- Lightweight: limited dependencies and < 400kb
- Incredibly easy to use and get started
- Limited dependencies and < 340kb
- JAX-RS compliant
- Easy on the developer and the metal
- Blazing fast!!!
[The latest Techempower benchmarks](https://www.techempower.com/benchmarks/) demonstrate __proteus__ outperforming 99% of all other web frameworks.
[The latest Techempower benchmarks](https://www.techempower.com/benchmarks/) demonstrate __proteus__ outperforming 99% of all other web frameworks

![Top 5 in Java Frameworks for Fortunes](https://github.com/noboomu/proteus-example/blob/master/src/main/resources/images/benchmark1.png?raw=true)

Expand All @@ -30,15 +31,34 @@ Getting Started
/bin/bash -e <(curl -fsSL https://raw.githubusercontent.com/noboomu/proteus-example/master/scripts/quickStart.sh)
```

- Open [http://localhost:8090/v1/openapi](http://localhost:8090/v1/openapi) for a v3 Swagger UI.
- Open [http://localhost:8090/v1/openapi](http://localhost:8090/v1/openapi) for a v3 OpenAPI UI.
- Open [http://localhost:8090/v1/swagger](http://localhost:8090/v1/openapi) for a v2 Swagger UI.

### As a dependency

```xml
<dependency>
<groupId>io.sinistral</groupId>
<artifactId>proteus-core</artifactId>
<version>0.3.6</version>
<version>0.4.0-SNAPSHOT</version>
</dependency>
```

Swagger v2 Support
```xml
<dependency>
<groupId>io.sinistral</groupId>
<artifactId>proteus-swagger</artifactId>
<version>0.4.0-SNAPSHOT</version>
</dependency>
```

OpenAPI v3 Support
```xml
<dependency>
<groupId>io.sinistral</groupId>
<artifactId>proteus-swagger</artifactId>
<version>0.4.0-SNAPSHOT</version>
</dependency>
```

Expand All @@ -47,12 +67,12 @@ Controllers

### Supported Controller Annotations

Controller classes respect standard Swagger / JAX-RS annotations:
Controller classes respect standard JAX-RS annotations:
```java
@Tags({@Tag(name = "benchmarks")})
@Path("/benchmarks")
@Produces((MediaType.APPLICATION_JSON))
@Consumes((MediaType.MEDIA_TYPE_WILDCARD))
public class DemoController
```

### Supported Method Annotations
Expand All @@ -61,13 +81,17 @@ Controller class methods respect standard Swagger / JAX-RS annotations:
```java
@GET
@Path("/plaintext")
@Produces((MediaType.TEXT_PLAIN))
@Operation(description = "Plaintext endpoint" )
@Produces((MediaType.TEXT_PLAIN))
public ServerResponse<ByteBuffer> plaintext(ServerRequest request)
{
return response("Hello, World!").textPlain();
}
```

> Swagger v2 annotations are supported when using the `proteus-swagger` module.
> OpenAPI v3 annotations are supported when using the `proteus-openapi` module.
Proteus has three built in annotations:

* @Blocking
Expand Down Expand Up @@ -113,7 +137,9 @@ Controller methods arguments support the following [JAX-RS annotations](https://
* ```javax.ws.rs.DefaultParam```
* Sets the default value of a method parameter.

## Return Types
## Methods and Return Types

###### *The examples below assume you've included the `proteus-openapi` module.

#### Performance
For total control and maximum performance the raw `HttpServerExchange` can be passed to the controller method.
Expand All @@ -123,25 +149,34 @@ Methods that take an `HttpServerExchange` as an argument should __not__ return a
In this case the method takes on __full responsibility__ for completing the exchange.

#### Convenience


The static method ```io.sinistral.proteus.server.ServerResponse.response``` helps create ```ServerResponse<T>``` instances that are the preferred return type for controller methods.

If the response object's `contentType` is not explicitly set, the `@Produces` annotation is used in combination with the `Accept` headers to determine the `Content-Type`.

For methods that should return a `String` or `ByteBuffer` to the client users can create responses like this:
```java
...
import static io.sinistral.proteus.server.ServerResponse.response;
...
@GET
@Path("/hello-world")
@Produces((MediaType.TEXT_PLAIN))
@Operation(description = "Serve a plaintext message using a ServerResponse")
public ServerResponse<ByteBuffer> plaintext(ServerRequest request, @QueryParam("message") String message)
{
return ServerResponse.response("Hello, World!").textPlain();
return response("Hello, World!").textPlain();
}
```
By default, passing a `String` to the static `ServerResponse.response` helper function will convert it into a `ByteBuffer`.

For other types of responses the following demonstrates the preferred style:
```java
...

import static io.sinistral.proteus.server.ServerResponse.response;
...
@GET
@Path("/world")
@Produces((MediaType.APPLICATION_JSON))
Expand All @@ -155,19 +190,26 @@ The entity can be set separately as well:
> this disables static type checking!
```java
...

import static io.sinistral.proteus.server.ServerResponse.response;
...
@GET
@Path("/world")
@Produces((MediaType.APPLICATION_JSON))
@Operation(description = "Return a world JSON object")
public io.sinistral.proteus.server.ServerResponse getWorld(Integer id, Integer randomNumber )
public ServerResponse getWorld(Integer id, Integer randomNumber )
{
return io.sinistral.proteus.server.ServerResponse.response().entity(new World(id,randomNumber));
return response().entity(new World(id,randomNumber));
}

```
`CompletableFuture<ServerResponse<T>>` can also be used as a response type:

```java
...
import static io.sinistral.proteus.server.ServerResponse.response;
...
@GET
@Path("/future/user")
@Operation(description = "Future user endpoint" )
Expand All @@ -180,6 +222,9 @@ public CompletableFuture<ServerResponse<User>> futureUser( ServerRequest request
In this case a handler will be generated with the following source code:

```java
...
import static io.sinistral.proteus.server.ServerResponse.response;
...
public void handleRequest(final io.undertow.server.HttpServerExchange exchange) throws java.lang.Exception {
CompletableFuture<ServerResponse<User>> response = examplesController.futureUser();
response.thenAccept( r -> r.applicationJson().send(this,exchange) )
Expand All @@ -200,6 +245,9 @@ Multipart/Form file uploads can be passed to the endpoint methods as a ```java.i

Optional parameters are also supported, here is a more complex endpoint demonstrating several parameter types:
```java
...
import static io.sinistral.proteus.server.ServerResponse.response;
...
@GET
@Path("/response/parameters/complex/{pathLong}")
@Operation(description = "Complex parameters")
Expand Down Expand Up @@ -242,9 +290,12 @@ public ServerResponse<Map<String,Object>> complexParameters(
Services
-------------

Proteus comes with three standard services that extend the ```io.sinistral.proteus.services.BaseService``` class.
Proteus has three standard services that extend the ```io.sinistral.proteus.services.BaseService``` class.

- __AssetsService__

Included in the `proteus-core` module.

The AssetsService mounts an asset directory at a given path and is configured in your ```application.conf``` file.

The default configuration:
Expand All @@ -262,6 +313,8 @@ Proteus comes with three standard services that extend the ```io.sinistral.prote
```
- __SwaggerService__

Included in the `proteus-swagger` module.

The SwaggerService generates a swagger-spec file from your endpoints and serves a swagger-ui and spec.

The default configuration serves the spec at `{application.path}/swagger.json` and the ui at `${application.path}/swagger`.
Expand All @@ -272,7 +325,6 @@ Proteus comes with three standard services that extend the ```io.sinistral.prote
```
swagger {
# the path that has an index.html template and theme css files
resourcePrefix="io/sinistral/proteus/swagger"
# swagger version
swagger: "2.0"
info {
Expand All @@ -299,6 +351,8 @@ Proteus comes with three standard services that extend the ```io.sinistral.prote

- __OpenAPIService__

Included in the `proteus-openapi` module.

The OpenAPIService generates an openapi-spec file from your endpoints and serves a swagger-ui and spec.

The default configuration serves the spec at `{application.path}/openapi.yaml` and the ui at `${application.path}/openapi`.
Expand All @@ -309,8 +363,6 @@ Proteus comes with three standard services that extend the ```io.sinistral.prote
```
openapi {

resourcePrefix="io/sinistral/proteus/server/tools/openapi"

basePath= ${application.path}"/openapi"

port = ${application.ports.http}
Expand Down Expand Up @@ -488,4 +540,4 @@ Built With
- [Swagger](http://swagger.io/) (annotations and swagger spec)
- [JAX-RS](http://docs.oracle.com/javaee/6/api/javax/ws/rs/package-summary.html) (annotations only)



8 changes: 5 additions & 3 deletions conf/logback.xml → core/conf/logback.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@

<logger name="org.apache.http" level="ERROR" />
<logger name="javax.activation" level="ERROR" />
<logger name="org.jboss" level="off" />


<logger name="io.netty" level="ERROR" />
<logger name="io.netty.handler" level="ERROR" />
Expand All @@ -20,7 +22,8 @@
<logger name="io.sinistral.proteus.server.tools.swagger" level="ERROR" />
<logger name="io.sinistral.proteus.server.handlers" level="ERROR" />
<logger name="io.sinistral.proteus.services" level="ERROR" />
<logger name="io.sinistral.proteus.server.tools" level="ERROR" />
<logger name="io.sinistral.proteus.openapi" level="ERROR" />
<logger name="io.sinistral.proteus.swagger" level="ERROR" />

<logger name="com.sun.jersey" level="ERROR" />

Expand All @@ -37,7 +40,6 @@
<logger name="java.jmx" level="ERROR" />

<logger name="org.apache.http.wire" level="ERROR" />
<logger name="com.wordnik" level="OFF" />

<logger name="sun.net" level="ERROR" />

Expand All @@ -48,7 +50,7 @@
<logger name="com.google.inject.internal" level="ERROR" />
<logger name="com.google.inject" level="ERROR" />

<root level="debug">
<root level="INFO">
<appender-ref ref="STDOUT" />
</root>
</configuration>
Loading

0 comments on commit 9e1eee1

Please sign in to comment.