Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/rockem/blink-java
Simplified pure Java http server
https://github.com/rockem/blink-java
http java pure server test
Last synced: 3 months ago
JSON representation
Simplified pure Java http server
- Host: GitHub
- URL: https://github.com/rockem/blink-java
- Owner: rockem
- License: apache-2.0
- Created: 2016-07-30T21:56:08.000Z (almost 8 years ago)
- Default Branch: master
- Last Pushed: 2022-05-20T20:49:38.000Z (about 2 years ago)
- Last Synced: 2024-01-24T17:08:46.452Z (6 months ago)
- Topics: http, java, pure, server, test
- Language: Java
- Homepage:
- Size: 209 KB
- Stars: 11
- Watchers: 3
- Forks: 1
- Open Issues: 10
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Lists
- awesome-opensource-israel - Blink-Java - Simple http server designed for use in tests, written in pure Java (no dependencies). ![GitHub last commit](https://img.shields.io/github/last-commit/rockem/blink-java?style=flat-square "GitHub last commit") ![GitHub top language](https://img.shields.io/github/languages/top/rockem/blink-java?style=flat-square) (Projects by main language / Old Projects)
README
# blink-java
[![CircleCI](https://circleci.com/gh/rockem/blink-java.svg?style=svg)](https://circleci.com/gh/rockem/blink-java)blink is a simplified http server, made primarily for using in tests.
It has no dependencies other than those that come with Oracle's Jdk
and it's inspired by Spark and Sinatra frameworks.## Dependency
### Maven
```xml
jcenter
https://jcenter.bintray.com/
```
```xmlorg.rockem
blink-java
0.5.3```
### Gradle
```groovy
repositories {
jcenter()
}
```
```groovy
dependencies {
compile 'org.rockem:blink-java:0.5.3'
}
```## Usage
### Hello World
#### Java
```java
new BlinkServer(1234) {{
get("/hello", (req, res) -> "Hello World");
}};
```
#### Groovy
```groovy
new BlinkServer(1234) {{
get("/hello", { req, res -> "Hello World" })
}}
```
### Path parameters
```java
new BlinkServer(1234) {{
delete("/hello/{id}", (req, res) -> "Delete " + req.pathParam("id"));
}};
```
### Default content type
```java
new BlinkServer(1234) {{
contentType("application/json")
get("/hello", (req, res) -> "{\"greeting\": \"Hello World\"}");
}};
```
### Request
```java
req.body() // request body
req.param("name") // Query parameter
req.pathParam("name") // Path parameter
req.uri() // Request uri
req.header("name") // header value
req.cookie("name") // cookie value
```
### Response
```java
res.status(201) // set retrun status code
res.header("name", "value") // Set header
res.type("type") // Set content type
res.cookie("name", "value") // Add/Update cookie
```