2018-06-10 00:43:02 +02:00
|
|
|
Principles
|
|
|
|
----------
|
2016-02-18 17:02:11 +01:00
|
|
|
|
2016-02-18 22:12:27 +01:00
|
|
|
**servant** has the following guiding principles:
|
2016-02-18 17:02:11 +01:00
|
|
|
|
|
|
|
- concision
|
|
|
|
|
|
|
|
This is a pretty wide-ranging principle. You should be able to get nice
|
|
|
|
documentation for your web servers, and client libraries, without repeating
|
|
|
|
yourself. You should not have to manually serialize and deserialize your
|
|
|
|
resources, but only declare how to do those things *once per type*. If a
|
|
|
|
bunch of your handlers take the same query parameters, you shouldn't have to
|
|
|
|
repeat that logic for each handler, but instead just "apply" it to all of
|
|
|
|
them at once. Your handlers shouldn't be where composition goes to die. And
|
|
|
|
so on.
|
|
|
|
|
|
|
|
- flexibility
|
|
|
|
|
|
|
|
If we haven't thought of your use case, it should still be easily
|
|
|
|
achievable. If you want to use templating library X, go ahead. Forms? Do
|
|
|
|
them however you want, but without difficulty. We're not opinionated.
|
|
|
|
|
|
|
|
- separation of concerns
|
|
|
|
|
2017-06-20 17:42:08 +02:00
|
|
|
Your handlers and your HTTP logic should be separate. True to the philosophy
|
2016-02-18 22:12:27 +01:00
|
|
|
at the core of HTTP and REST, with **servant** your handlers return normal
|
2016-02-18 17:02:11 +01:00
|
|
|
Haskell datatypes - that's the resource. And then from a description of your
|
2016-02-18 22:12:27 +01:00
|
|
|
API, **servant** handles the *presentation* (i.e., the Content-Types). But
|
2016-02-18 17:02:11 +01:00
|
|
|
that's just one example.
|
|
|
|
|
|
|
|
- type safety
|
|
|
|
|
|
|
|
Want to be sure your API meets a specification? Your compiler can check
|
|
|
|
that for you. Links you can be sure exist? You got it.
|
|
|
|
|
|
|
|
To stick true to these principles, we do things a little differently than you
|
|
|
|
might expect. The core idea is *reifying the description of your API*. Once
|
|
|
|
reified, everything follows. We think we might be the first web framework to
|
|
|
|
reify API descriptions in an extensible way. We're pretty sure we're the first
|
|
|
|
to reify it as *types*.
|