GithubHelp home page GithubHelp logo

cak / server.swift Goto Github PK

View Code? Open in Web Editor NEW
9.0 3.0 1.0 24 KB

A simple server for testing HTTP requests powered by SwiftNIO and swift sh

License: MIT License

Swift 100.00%
server-side-swift swiftnio swift-sh

server.swift's Introduction

server.swift

A simple server for testing HTTP requests powered by SwiftNIO and swift sh.

server.swift supports only SwiftNIO 2 and Swift 5.0

Usage

Install swift sh

brew install mxcl/made/swift-sh

More instructions for swift sh are available at https://github.com/mxcl/swift-sh/.

Run server.swift

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:8000

Alternatively, you can clone the repository and run ‌swift sh server.swift

Command Line Arguments

The hostname and port can be specified with --hostname and --port

swift sh server.swift --hostname "localhost" --port 8080
Starting server.swift on [IPv6]::1/::1:8080

Examples

GET request:

curl -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"
}

POST request:

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"
}

Contributing

Send a pull request or create an issue.

server.swift's People

Contributors

cak avatar yasumoto avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

yasumoto

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.