All Projects → sboehler → servant-starter-app

sboehler / servant-starter-app

Licence: BSD-3-Clause license
A template to get started with servant, postgresql-simple and cookie authentication

Programming Languages

haskell
3896 projects
Nix
1067 projects
shell
77523 projects

Projects that are alternatives of or similar to servant-starter-app

line-bot-sdk
🍥 Haskell向けLINE Messaging API SDK
Stars: ✭ 31 (+82.35%)
Mutual labels:  servant
haskell-realworld-example
A Haskell implementation of realworld.io
Stars: ✭ 39 (+129.41%)
Mutual labels:  servant
hackernews
📰 HackerNews API
Stars: ✭ 40 (+135.29%)
Mutual labels:  servant
haskell-tic-tac-toe
A multiplayer web real-time implementation of the famous Tic Tac Toe game in Haskell.
Stars: ✭ 51 (+200%)
Mutual labels:  servant
servant-beam-realworld-example-app
Exemplary fullstack Medium.com clone powered by Servant and Beam
Stars: ✭ 33 (+94.12%)
Mutual labels:  servant
servant-static-th
Embed a directory of static files in your application and serve them from your Servant server
Stars: ✭ 14 (-17.65%)
Mutual labels:  servant

servant-starter-app

A fully functional app template for starting a new servant app with cookie authentication, postgresql-simple and postgresql-simple-migrations.

This version uses servant-auth for authentication, which is poised to become the standard authentication framework for servant

Check out the servant-auth-cookie branch for a version that uses servant-auth-cookie.

This is the result of my own Haskell learning experience - reviews, helpful suggestions & pull requests are welcome!

Instructions

Prerequisites: Install stack and have a PostgreSQL database named 'servant-starter-app' running on port 5432, without authentication (see src/Database.hs if you require additional configuration).

Starting the server using stack:

stack setup
stack run

Starting the server using nix:

nix-shell
cabal new-run

Testing the API:

# create a new user
curl -X POST -v -H "Content-Type: application/json" -d '{"credentialsEmail":"[email protected]", "credentialsPassword":"a password"}' localhost:4000/user

# log in
curl -X POST -b cookies -c cookies -v -H "Content-Type: application/json" -d '{"credentialsEmail":"[email protected]", "credentialsPassword":"a password"}' localhost:4000/session

# access the protected user endpoint, which returns the user as a JSON object
# Note that servant-auth uses XSRF protection, so you need to set a header field (it only works once, as the xsrf cookie is renewed after each request
curl -b cookies -c cookies -v -H "Content-Type: application/json" -H "X-XSRF-TOKEN: <enter xsrf token from cookies file here>" localhost:4000/user


# log out (doesn't work yet)
curl -X DELETE -b cookies -c cookies -v -H "Content-Type: application/json" localhost:4000/session

# verify the user endpoint is not accessible anymore
curl -b cookies -c cookies -v -H "Content-Type: application/json" localhost:4000/user
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].