在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称:swift-server/http开源软件地址:https://github.com/swift-server/http开源编程语言:Swift 68.8%开源软件介绍:Swift Server Project HTTP APIsIt remains here for historical interest only. Getting StartedHello WorldThe following code implements a very simple "Hello World!" server: import Foundation
import HTTP
func hello(request: HTTPRequest, response: HTTPResponseWriter ) -> HTTPBodyProcessing {
response.writeHeader(status: .ok)
response.writeBody("Hello, World!")
response.done()
return .discardBody
}
let server = HTTPServer()
try! server.start(port: 8080, handler: hello)
RunLoop.current.run() The Data that is received as part of the request body is made available to the closure that is returned by the Echo ServerThe following code implements a very simple Echo server that responds with the contents of the incoming request: import Foundation
import HTTP
func echo(request: HTTPRequest, response: HTTPResponseWriter ) -> HTTPBodyProcessing {
response.writeHeader(status: .ok)
return .processBody { (chunk, stop) in
switch chunk {
case .chunk(let data, let finishedProcessing):
response.writeBody(data) { _ in
finishedProcessing()
}
case .end:
response.done()
default:
stop = true
response.abort()
}
}
}
let server = HTTPServer()
try! server.start(port: 8080, handler: echo)
RunLoop.current.run() As the Echo server needs to process the request body data and return it in the reponse, the Once any data chunk has been processed, When the response is complete, API DocumentationFull Jazzy documentation of the API is available here: ContributingFeedbackWe are actively seeking feedback on this prototype and your comments are extremely valuable. If you have any comments on the API design, the implementation, or any other aspects of this project, please email the Writing CodeWe also welcome code contributions. If you are developing on macOS, you may want to work within Xcode. This project uses the Swift Package Manager. To work on this project within Xcode you can run the Swift Package Manager command AcknowledgementsThis project is based on an inital proposal from @weissi on the swift-server-dev mailing list: |
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论