0Pricing
Scala for Backend Engineering & Functional Programming · Lesson

Serving the Application

Run a functional web server.

Ember Server

http4s runs your HttpApp[F] on a backend. The default modern choice is Ember, a pure-Scala server built on cats-effect and fs2, available as org.http4s.ember.server.EmberServerBuilder.

Older apps may use Blaze, but Ember is the recommended path going forward.

// build.sbt
// "org.http4s" %% "http4s-ember-server" % http4sV

Building the Server

EmberServerBuilder.default[F] gives a builder you configure fluently: bind host and port, attach the app, then call .build to get a Resource[F, Server].

Using a Resource guarantees the socket is released on shutdown.

import com.comcast.ip4s._
import org.http4s.ember.server.EmberServerBuilder

EmberServerBuilder.default[IO]
  .withHost(ipv4"0.0.0.0")
  .withPort(port"8080")
  .withHttpApp(app)
  .build

All lessons in this course

  1. Routes and HttpRoutes
  2. Requests and Responses
  3. JSON Endpoints
  4. Serving the Application
← Back to Scala for Backend Engineering & Functional Programming