Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/httpswift/swifter
Tiny http server engine written in Swift programming language.
https://github.com/httpswift/swifter
http server swift web
Last synced: about 19 hours ago
JSON representation
Tiny http server engine written in Swift programming language.
- Host: GitHub
- URL: https://github.com/httpswift/swifter
- Owner: httpswift
- License: bsd-3-clause
- Created: 2014-06-06T17:07:31.000Z (over 10 years ago)
- Default Branch: stable
- Last Pushed: 2024-03-17T20:32:47.000Z (9 months ago)
- Last Synced: 2024-12-08T01:33:04.818Z (4 days ago)
- Topics: http, server, swift, web
- Language: Swift
- Size: 11.1 MB
- Stars: 3,910
- Watchers: 101
- Forks: 537
- Open Issues: 117
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
- awesome-ios - Swifter - Tiny http server engine written in Swift programming language. (Server / Keychain)
- awesome-swift - swifter - Http server with routing handler. (Libs / Network)
- awesome-swift - swifter - Http server with routing handler. (Libs / Network)
- awesome-ios-star - Swifter - Tiny http server engine written in Swift programming language. (Server / Keychain)
- fucking-awesome-swift - swifter - Http server with routing handler. (Libs / Network)
- Awesome-Swift-Packages - Swifter - Tiny http server engine written in Swift programming language.. (Server)
- awesome-swift - swifter - Tiny http server engine written in Swift programming language. ` 📝 2 months ago` (Network [🔝](#readme))
README
![Platform](https://img.shields.io/badge/Platform-Linux%20&%20OSX%20&%20tvOS-4BC51D.svg?style=flat)
![Swift](https://img.shields.io/badge/Swift-4.x,_5.0-4BC51D.svg?style=flat)
![Protocols](https://img.shields.io/badge/Protocols-HTTP%201.1%20&%20WebSockets-4BC51D.svg?style=flat)
[![CocoaPods](https://img.shields.io/cocoapods/v/Swifter.svg?style=flat)](https://cocoapods.org/pods/Swifter)
[![Carthage Compatible](https://img.shields.io/badge/Carthage-compatible-4BC51D.svg?style=flat)](https://github.com/Carthage/Carthage)### What is Swifter?
Tiny http server engine written in [Swift](https://developer.apple.com/swift/) programming language.
### Branches
`* stable` - lands on CocoaPods and others. Supports the latest non-beta Xcode and SPM. Stable.`* master` - stable branch plus experimental web-framework layer.
`* 2.0 ` - next version of Swifter (async IO). Experimental.
### How to start?
```swift
let server = HttpServer()
server["/hello"] = { .ok(.htmlBody("You asked for \($0)")) }
server.start()
```### How to load HTML by string?
```swift
let server = HttpServer()
server[path] = { request in
return HttpResponse.ok(.text(""))
}
server.start()
```### How to share files?
```swift
let server = HttpServer()
server["/desktop/:path"] = shareFilesFromDirectory("/Users/me/Desktop")
server.start()
```
### How to redirect?
```swift
let server = HttpServer()
server["/redirect"] = { request in
return .movedPermanently("http://www.google.com")
}
server.start()
```
### How to HTML ?
```swift
let server = HttpServer()
server["/my_html"] = scopes {
html {
body {
h1 { inner = "hello" }
}
}
}
server.start()
```
### How to WebSockets ?
```swift
let server = HttpServer()
server["/websocket-echo"] = websocket(text: { session, text in
session.writeText(text)
}, binary: { session, binary in
session.writeBinary(binary)
})
server.start()
```
### CocoaPods? Yes.
```ruby
use_frameworks!pod 'Swifter', '~> 1.5.0'
```### Carthage? Also yes.
```
github "httpswift/swifter" ~> 1.5.0
```### Swift Package Manager.
```swift
import PackageDescriptionlet package = Package(
name: "MyServer",
dependencies: [
.package(url: "https://github.com/httpswift/swifter.git", .upToNextMajor(from: "1.5.0"))
]
)
```### Docker.
```
docker run -d -p 9080:9080 -v `pwd`:/Swifter -w /Swifter --name Swifter swift bash -c "swift run"
```