Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/cezarywojcik/Swift-Server
A very basic proof-of-concept Swift HTTP server that does not require Foundation
https://github.com/cezarywojcik/Swift-Server
Last synced: about 1 month ago
JSON representation
A very basic proof-of-concept Swift HTTP server that does not require Foundation
- Host: GitHub
- URL: https://github.com/cezarywojcik/Swift-Server
- Owner: cezarywojcik
- License: mit
- Created: 2015-06-27T08:20:55.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2015-12-04T10:53:53.000Z (about 9 years ago)
- Last Synced: 2024-10-16T01:44:38.812Z (about 2 months ago)
- Language: Swift
- Homepage:
- Size: 14.6 KB
- Stars: 56
- Watchers: 5
- Forks: 6
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-swift-cn - Swift-Server - Currently, a very basic proof-of-concept Swift HTTP server that does not require Foundation. (Libs / Network)
README
# Swift Server
## Introduction
This is very rough and basic HTTP server written in Swift without using `Foundation`.
This is partially based on the [Swifter](https://github.com/glock45/swifter) repo, however, the point is to eliminate the need for Apple's `Foundation` library to prepare for using Swift on Linux.
This is built using [Swift Script Include](https://github.com/cezarywojcik/Swift-Script-Include) to enable using multiple files for Swift scripts and runs without Xcode purely on the terminal.
## Installation Notes
This is built using Swift 2, and requires your command-line `swift` to be using Swift 2 as well. You can check your Swift version by running `swift --version` in your terminal. If you are running Swift 1.2 instead of 2.0, first, make sure that you have the Xcode 7 beta installed. Next, run the following command:
```
sudo xcode-select -switch /Applications/Xcode-beta.app/Contents/Developer
```## Running
To run the project, simply type `make run` in the project directory.
Visit [`http://127.0.0.1:3000`](http://127.0.0.1:3000) in your web browser to see a friendly "Hello, World!" message. The HTTP request will be printed in your terminal.
## Example Code
The functionality is currently very basic. The code below shows what the server can currently do.
```
include "lib/server.swift"let app = Server(port: port)
app.run() {
request, response -> () in
print(request.raw)
response.sendRaw("HTTP/1.1 200 OK\n\nHello, World!\n")
}```