mirror of
https://github.com/swisspol/GCDWebServer.git
synced 2026-04-24 00:00:04 +08:00
Merge pull request #60 from pvblivs/master
Adding instructions for Swift command line tool
This commit is contained in:
@@ -57,6 +57,29 @@ Hello World
|
|||||||
|
|
||||||
These code snippets show how to implement a custom HTTP server that runs on port 8080 and returns a "Hello World" HTML page to any request. Since GCDWebServer uses GCD blocks to handle requests, no subclassing or delegates are needed, which results in very clean code.
|
These code snippets show how to implement a custom HTTP server that runs on port 8080 and returns a "Hello World" HTML page to any request. Since GCDWebServer uses GCD blocks to handle requests, no subclassing or delegates are needed, which results in very clean code.
|
||||||
|
|
||||||
|
**OS X Swift version (command line tool):**
|
||||||
|
|
||||||
|
***webServer.swift***
|
||||||
|
```swift
|
||||||
|
import Foundation
|
||||||
|
|
||||||
|
let webServer = GCDWebServer()
|
||||||
|
|
||||||
|
webServer.addDefaultHandlerForMethod("GET", requestClass: GCDWebServerRequest.self) { request in
|
||||||
|
return GCDWebServerDataResponse(HTML:"<html><body><p>Hello World</p></body></html>")
|
||||||
|
}
|
||||||
|
|
||||||
|
webServer.runWithPort(8080, bonjourName: nil)
|
||||||
|
|
||||||
|
println("Visit \(webServer.serverURL) in your web browser")
|
||||||
|
```
|
||||||
|
|
||||||
|
***WebServer-Bridging-Header.h***
|
||||||
|
```objectivec
|
||||||
|
#import "GCDWebServer.h"
|
||||||
|
#import "GCDWebServerDataResponse.h"
|
||||||
|
```
|
||||||
|
|
||||||
**OS X version (command line tool):**
|
**OS X version (command line tool):**
|
||||||
```objectivec
|
```objectivec
|
||||||
#import "GCDWebServer.h"
|
#import "GCDWebServer.h"
|
||||||
|
|||||||
Reference in New Issue
Block a user