Skip to content

Commit 0f89c43

Browse files
committed
Define the Users API as a type
1 parent dcdc67c commit 0f89c43

2 files changed

Lines changed: 24 additions & 0 deletions

File tree

how-does-servants-type-dsl-work.cabal

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,6 @@ maintainer: hi@bradparker.com
99
executable server
1010
main-is: Main.hs
1111
build-depends: base ^>=4.12.0.0
12+
, servant-server
1213
hs-source-dirs: src
1314
default-language: Haskell2010

src/Main.hs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,29 @@
1+
{-# LANGUAGE DataKinds #-}
2+
{-# LANGUAGE TypeOperators #-}
13
{-# OPTIONS_GHC -Wall #-}
24

35
module Main where
46

7+
import Servant
8+
( (:<|>)
9+
, (:>)
10+
, Capture
11+
, Get
12+
, JSON
13+
)
14+
15+
data User = User
16+
17+
type UsersIndex =
18+
Get '[JSON] [User]
19+
20+
type UsersShow =
21+
Capture "username" String
22+
:> Get '[JSON] User
23+
24+
type UsersAPI =
25+
"users"
26+
:> (UsersIndex :<|> UsersShow)
27+
528
main :: IO ()
629
main = putStrLn "Hello, Haskell!"

0 commit comments

Comments
 (0)