Scala FS2 and HTTP4S

Duration
1 day
Online Duration
1 day

A solid understanding of fs2 and http4s is essential for a more comprehensive grasp of Scala. If you are looking for an efficient and speedy polymorphic stream processing library, then FS2, or Functional Streams for Scala, is for you. It is compatible with Cats-effect typeclasses and can be used with other effect libraries. Built on FS2, HTTP4S is the ideal companion topic for this course and is the minimal Scala interface for your HTTP services.

Students should be familiar with the Scala programming language, cats and cats-effect. We advice students to follow our SCALA-CATS course

Please find the course objectives below:

fs2

  • Introduction to fs2
  • Compare fs2 to other streaming libraries
  • Defining pure streams
  • using core operations (map, flatMap, take, …)
  • Combining Streams
  • Define effectful streams
  • Understand stream compilation to F[_]
  • List key fs2 API (Stream, Pipe, Chunk, Pull, …)
  • Transforming values using pipes
  • Handling errors
  • Building Retry logic
  • Building declarative flows
  • Handling and releasing Resources
  • Introduction to Concurrency

http4s

  • Introduce https as a functional HTTP client/server
  • Introduce its Architecture
  • Understand the relevance of Kleisli, MonoidK and other typeclasses
  • Understand the role of fs2
  • Introduce Blaze

The Server and APIs/DSL

  • Configure the BlazeServer
  • Introduce the server DSL
  • Build polymorphic http4s code
  • Understand make aResponse (body, headers)
  • How map HTTP Requests
  • Extract Path Parameters
  • Use Query Parameters
  • Introduce Entity Handing and codecs
  • Understand how EntityDecoder/EntityEncoder works
  • Using built-in codecs (strings, fs2 Stream, …)
  • Introduce/Recap Circe for Json handling
  • Integrate http4s and circe
  • Accessing the request body (for POST)
  • Adding request Validation using cats
  • Introduce and use Middleware
  • Define your own Middleware
  • Apply Middleware to your routes (logging, Authentication, CORS, etc)

The Client API/DSL

  • Set up a Blaze client
  • Introduce the client API
  • Making requests use the Client DSL
  • Handling the responses
  • Working with Headers
  • Discuss client middleware (retry, follow-redirects,.. )
For an onsite course please contact us