<commit_before># `zap` :zap:

[![GitHub issues](https://img.shields.io/github/issues/oldaniel/zap.svg)](https://github.com/oldaniel/zap/issues)

The mission of `zap` is, to deliver a basic, but fast rust web framework .

## About

**This code is based on tokio's minihttp project, so a big thanks to them.** ([source](https://github.com/tokio-rs/tokio-minihttp))

## How to use

Add the following to your `Cargo.toml`:
```toml
[dependencies]
zap = "0.0.1"
```

## Speed

So `zap` is not only fast, it is wapping **2.8** times faster than [iron](https://github.com/iron/iron), which is based on [hyper](https://github.com/hyperium/hyper). Benchmarks below:

### Benchmark Code

**Iron**

This code had been taken from the [ironframework.io](http://ironframework.io) webpage.

```rust
extern crate iron;

use iron::prelude::*;
use iron::status;

fn main() {
    fn hello_world(_: &mut Request) -> IronResult<Response> {
        Ok(Response::with((status::Ok, "Hello World!")))
    }

    let _server = Iron::new(hello_world).http("localhost:3000").unwrap();
    println!("On 3000");
}
```

**Zap**

This example can be run, by:

```
$ git clone https://github.com/oldaniel/zap && cd zap
$ cargo run --example hello-world --release
```

```rust
extern crate zap;

use std::io;

use zap::{Server, Http, Handler, ZapResult, Request, Response};

struct HelloWorld;

impl Handler for HelloWorld {
    type Request = Request;
    type Response = Response;
    type Error = io::Error;
    type Future = ZapResult;

    fn call(&self, _: Request) -> ZapResult {
        let mut resp = Response::new();

        resp.body("Hello World!");

        resp.ok()
    }
}

fn main() {
    let addr = "0.0.0.0:8080".parse().unwrap();
    let mut server = Server::new(Http, addr);
    server.threads(8);
    server.serve(|| Ok(HelloWorld));
}
```

### Benchmark Results

The benchmark results have been computed with this command: `wrk -t16 -c500 -d10s http://127.0.0.1:8080 --latency`

Technical details about the server:

- Intel Core I7-6700K, hyper-threaded
- 16GB RAM, 2400MHZ

**Iron**

```
Running 10s test @ http://127.0.0.1:8080
  16 threads and 500 connections
  Thread Stats   Avg      Stdev     Max   +/- Stdev
    Latency   214.85us  622.27us  78.67ms   99.24%
    Req/Sec    77.20k    51.31k  191.91k    51.98%
  Latency Distribution
     50%  183.00us
     75%  219.00us
     90%  304.00us
     99%  746.00us
  3103506 requests in 10.09s, 337.41MB read
Requests/sec: 307581.17
Transfer/sec:     33.44MB
```

**Zap**

```
Running 10s test @ http://127.0.0.1:8080
  16 threads and 500 connections
  Thread Stats   Avg      Stdev     Max   +/- Stdev
    Latency     0.96ms    1.36ms  20.38ms   87.20%
    Req/Sec    56.12k    18.31k  142.46k    70.97%
  Latency Distribution
     50%  396.00us
     75%    1.26ms
     90%    2.73ms
     99%    6.18ms
  8982095 requests in 10.09s, 436.87MB read
Requests/sec: 889894.86
Transfer/sec:     43.28MB
```

## Todo

Some things we still need to make:

- [ ] Make it faster
- [ ] URL and body parsing
- [ ] Request key storing

## Credits & License

A project by [<NAME>](https://github.com/oldaniel).

[![GitHub license](https://img.shields.io/badge/license-MIT-blue.svg)](https://raw.githubusercontent.com/oltmannsdaniel/zap/master/LICENSE)
<commit_msg>Some more `shields`<commit_after># `zap` :zap:

[![GitHub issues](https://img.shields.io/github/issues/oldaniel/zap.svg)](https://github.com/oldaniel/zap/issues)
[![Crates.io](https://img.shields.io/crates/d/zap.svg)](https://github.com/oldaniel/zap)
[![Crates.io](https://img.shields.io/crates/v/zap.svg)](https://github.com/oldaniel/zap)

The mission of `zap` is, to deliver a basic, but fast rust web framework .

## About

**This code is based on tokio's minihttp project, so a big thanks to them.** ([source](https://github.com/tokio-rs/tokio-minihttp))

## How to use

Add the following to your `Cargo.toml`:
```toml
[dependencies]
zap = "0.0.1"
```

## Speed

So `zap` is not only fast, it is wapping **2.8** times faster than [iron](https://github.com/iron/iron), which is based on [hyper](https://github.com/hyperium/hyper). Benchmarks below:

### Benchmark Code

**Iron**

This code had been taken from the [ironframework.io](http://ironframework.io) webpage.

```rust
extern crate iron;

use iron::prelude::*;
use iron::status;

fn main() {
    fn hello_world(_: &mut Request) -> IronResult<Response> {
        Ok(Response::with((status::Ok, "Hello World!")))
    }

    let _server = Iron::new(hello_world).http("localhost:3000").unwrap();
    println!("On 3000");
}
```

**Zap**

This example can be run, by:

```
$ git clone https://github.com/oldaniel/zap && cd zap
$ cargo run --example hello-world --release
```

```rust
extern crate zap;

use std::io;

use zap::{Server, Http, Handler, ZapResult, Request, Response};

struct HelloWorld;

impl Handler for HelloWorld {
    type Request = Request;
    type Response = Response;
    type Error = io::Error;
    type Future = ZapResult;

    fn call(&self, _: Request) -> ZapResult {
        let mut resp = Response::new();

        resp.body("Hello World!");

        resp.ok()
    }
}

fn main() {
    let addr = "0.0.0.0:8080".parse().unwrap();
    let mut server = Server::new(Http, addr);
    server.threads(8);
    server.serve(|| Ok(HelloWorld));
}
```

### Benchmark Results

The benchmark results have been computed with this command: `wrk -t16 -c500 -d10s http://127.0.0.1:8080 --latency`

Technical details about the server:

- Intel Core I7-6700K, hyper-threaded
- 16GB RAM, 2400MHZ

**Iron**

```
Running 10s test @ http://127.0.0.1:8080
  16 threads and 500 connections
  Thread Stats   Avg      Stdev     Max   +/- Stdev
    Latency   214.85us  622.27us  78.67ms   99.24%
    Req/Sec    77.20k    51.31k  191.91k    51.98%
  Latency Distribution
     50%  183.00us
     75%  219.00us
     90%  304.00us
     99%  746.00us
  3103506 requests in 10.09s, 337.41MB read
Requests/sec: 307581.17
Transfer/sec:     33.44MB
```

**Zap**

```
Running 10s test @ http://127.0.0.1:8080
  16 threads and 500 connections
  Thread Stats   Avg      Stdev     Max   +/- Stdev
    Latency     0.96ms    1.36ms  20.38ms   87.20%
    Req/Sec    56.12k    18.31k  142.46k    70.97%
  Latency Distribution
     50%  396.00us
     75%    1.26ms
     90%    2.73ms
     99%    6.18ms
  8982095 requests in 10.09s, 436.87MB read
Requests/sec: 889894.86
Transfer/sec:     43.28MB
```

## Todo

Some things we still need to make:

- [ ] Make it faster
- [ ] URL and body parsing
- [ ] Request key storing

## Credits & License

A project by [<NAME>](https://github.com/oldaniel).

[![GitHub license](https://img.shields.io/badge/license-MIT-blue.svg)](https://raw.githubusercontent.com/oltmannsdaniel/zap/master/LICENSE)

{'fraction_non_alphanumeric': 0.1543465405085748, 'fraction_numerical': 0.07569485511531639, 'mean_word_length': 3.019607843137255, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 11, 'https://': 22, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 8, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4636362', 'n_tokens_mistral': 2821, 'n_tokens_neox': 2437, 'n_words': 652}