Giter Site home page Giter Site logo

sboehler / servant-starter-app Goto Github PK

View Code? Open in Web Editor NEW
18.0 2.0 3.0 19 KB

A template to get started with servant, postgresql-simple and cookie authentication

License: BSD 3-Clause "New" or "Revised" License

Haskell 82.66% Nix 16.28% Shell 1.06%
haskell servant authentication

servant-starter-app's Introduction

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

servant-starter-app's People

Contributors

sboehler avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.