3 min read

Before learning why you should be excited about this new web framework for rust, let me brief you about what the buzz is all about. Warp is a web server implementing WAI- the Web Application Interface. The WAI is an interface between servers and applications in Haskell, that has the ability to allow multiple apps and frameworks to share backends and middlewares. Have I got your attention yet? Read on to learn more about Warp v0.1

The Warp Architecture

The type of a WAI application is as follows:

type Application = Request -> ResourceT IO Response

This simply means that: a WAI Application takes a Request and returns a Response, used in the context where I/O is possible and resources are well managed. The process happens in 3 stages.

  1. Spawning a dedicated user thread after accepting a HTTP connection. It receives an HTTP request from a client and parses it to Request.
  2. Warp gives the Request to the WAI application and receives a Response from it.
  3. Warp builds an HTTP response based on the Response value and sends it back to the client.

The process could be better understood if you refer to the figure below-

The Architecture of Warp

 The architecture of Warp

(Source : Aosabook.org)

The user thread repeats this procedure as many times as needed and terminates itself on the occurrence of one of the two instances- One: when the connection is closed by the peer or an invalid request is received and Two: if a significant amount of data is not received after a certain period of time (i.e., a timeout has occurred).

What makes Warp interesting?

You can write a web application directly against WAI and have it run on Warp, though that’s lower level than what most frameworks provide. Web frameworks like Yesod, Servant, Scotty, Spock, and others are all built on top of Warp. It’s a framework that is fast,  asynchronous, and benefits from all the improvements that power Linkerd.

What’s unique about this web framework is its “FILTER SYSTEM”. A filter is just a function, that simply put, takes an input and returns an output. This output can either be some app-specific type that a user wishes to pass around or a reply that needs to be sent back as a HTTP response. As simple as this may sound, you are in for a major curveball. There are these “combinators” that exist on the Filter that allow composing smaller filters into larger ones, thus allowing the modularization and re-use of any part of your web server. This combination of results is smart: it automatically discards results that are not needed, instead of passing worthless unit arguments to your handlers.

Besides this upgrade, Warp also provides the common web server features like-

  • Path routing and parameter extraction
  • Header requirements and extraction
  • Query string deserialization
  • JSON and Form bodies
  • Static Files and Directories
  • Websockets
  • Access logging
  • And others, and more being added.

To add to all these amazing features, Warp has been released not only to explore Filter system, but also to explore some ideas before solidifying another soon-to-be-released web framework- Tower-web.

To know more about this super-easy, composable, web framework for warp speeds that is making all the buzz in the Rust Community, head over to the official documentation.

Read Next

Rust 1.28 is here with global allocators, nonZero types and more

Will Rust Replace C++?

Say hello to Sequoia: a new Rust based OpenPGP library to secure your apps


Subscribe to the weekly Packt Hub newsletter. We'll send you this year's Skill Up Developer Skills Report.

* indicates required

LEAVE A REPLY

Please enter your comment!
Please enter your name here