A simple server for testing HTTP requests powered by SwiftNIO and swift sh.
server.swift supports only SwiftNIO 2 and Swift 5.0
brew install mxcl/made/swift-shMore instructions for
swift share available at https://github.com/mxcl/swift-sh/.
swift sh <(curl -L https://github.com/cak/server.swift/raw/master/server.swift)Starting server.swift on [IPv4]0.0.0.0/0.0.0.0:8000Alternatively, you can clone the repository and run swift sh server.swift
The hostname and port can be specified with --hostname and --port
swift sh server.swift --hostname "localhost" --port 8080Starting server.swift on [IPv6]::1/::1:8080curl -i "http://localhost:8000/get?foo=bar" \
     -H 'origin: https://serversideswift.dev'Console
GET request to /get?foo=bar from [IPv6]::1/::1:52978
{
  "path" : "\/get?foo=bar",
  "method" : "GET",
  "headers" : {
    "Accept" : "*\/*",
    "Host" : "localhost:8000",
    "origin" : "https:\/\/serversideswift.dev",
    "User-Agent" : "curl\/7.54.0"
  },
  "origin" : "[IPv6]::1\/::1:52978"
}HTTP Response
HTTP/1.1 200 OK
Server: server.swift
content-type: application/json; charset=utf-8
Content-Length: 244
access-control-allow-origin: https://serversideswift.dev
access-control-allow-headers: accept, authorization, content-type, origin, x-requested-with
access-control-allow-methods: GET, POST, PUT, OPTIONS, DELETE, PATCH
access-control-max-age: 600
{
  "path" : "\/get?foo=bar",
  "method" : "GET",
  "headers" : {
    "Accept" : "*\/*",
    "Host" : "localhost:8000",
    "origin" : "https:\/\/serversideswift.dev",
    "User-Agent" : "curl\/7.54.0"
  },
  "origin" : "[IPv6]::1\/::1:52978"
}curl -i -X "POST" "http://localhost:8000/post" \
     -H 'Content-Type: application/json; charset=utf-8' \
     -d $'{
  "foo": "bar"
}'Console
POST request to /post from [IPv4]127.0.0.1/127.0.0.1:51299
{
  "path" : "\/post",
  "body" : "{\n  \"foo\": \"bar\"\n}",
  "method" : "POST",
  "headers" : {
    "Content-Type" : "application\/json; charset=utf-8",
    "Host" : "localhost:8000",
    "Accept" : "*\/*",
    "Content-Length" : "18",
    "User-Agent" : "curl\/7.54.0"
  },
  "origin" : "[IPv4]127.0.0.1\/127.0.0.1:51299"
}HTTP Response
HTTP/1.1 200 OK
Server: server.swift
content-type: application/json; charset=utf-8
Content-Length: 327
{
  "path" : "\/post",
  "body" : "{\n  \"foo\": \"bar\"\n}",
  "method" : "POST",
  "headers" : {
    "Accept" : "*\/*",
    "Host" : "localhost:8000",
    "Content-Length" : "18",
    "Content-Type" : "application\/json; charset=utf-8",
    "User-Agent" : "curl\/7.54.0"
  },
  "origin" : "[IPv4]127.0.0.1\/127.0.0.1:49362"
}Send a pull request or create an issue.