Skip to content

Instantly share code, notes, and snippets.

@sturdysturge
Created April 18, 2022 21:51
Show Gist options
  • Select an option

  • Save sturdysturge/3f8eb8a56fccaab8a72e8dc87bbf9dcb to your computer and use it in GitHub Desktop.

Select an option

Save sturdysturge/3f8eb8a56fccaab8a72e8dc87bbf9dcb to your computer and use it in GitHub Desktop.
import Plot
import Vapor
extension Response.Body {
init(html: HTML) {
self.init(string: html.render())
}
}
extension Response {
convenience init(_ html: HTML) {
self.init(status: .ok, headers: ["Content-Type": "text/html"], body: .init(html: html))
}
}
extension HTML {
func response() -> Response {
Response(self)
}
}
extension HTML: ResponseEncodable {
public func encodeResponse(for request: Request) -> EventLoopFuture<Response> {
request.eventLoop.makeSucceededFuture(Response(self))
}
}
@saroar
Copy link

saroar commented Sep 11, 2023

AsyncResponseEncodable :)

extension HTML: AsyncResponseEncodable {
  public func encodeResponse(for request: Request) async -> Response {
      return Response(self)
  }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment