Awesome
yesod-rest
A Yesod scaffolding site with Postgres backend. It provides a JSON API
backend as a
separate subsite. The
primary purpose of this repository is to use Yesod as a API server
backend and do the frontend development using a tool like React or
Angular. The current code includes a basic hello world using
React and
Babel which is bundled finally by
webpack and added in the handler
getHomeR
in a type safe manner.
Features
- Provides an API server.
- Boilerplate for writing frontend code using React Javascript ecosystem is provided. (can be easily adapted to other tools like Angular, etc.)
- Brings all the advantage of Yesod - type safe urls, simple DSL for routes etc.
Setup and Execution steps
- Install Stack.
- sudo apt-get install libpq-dev postgresql postgresql-contrib (For Debian based systems)
- cd yesod-rest
- stack build yesod-bin cabal-install --install-ghc
- cd static && npm install
- npm run webpack
- stack build
- stack exec -- yesod devel (Runs development server)
- (Or) stack exec yesod-rest
Adding a API Route
Add the route to config/apiRoutes
file and define your corresponding
handler function in API.hs
.
Demo:
You can see the rest.hurl
FAQ
- I see this error on
stack exec yesod-rest
:
yesod-rest: libpq: failed (could not connect to server: Connection refused
Is the server running on host "localhost" (127.0.0.1) and accepting
TCP/IP connections on port 5432?)
You most likely haven't installed the postgres server. For Ubuntu systems, it can be done by:
sudo apt-get install postgresql postgresql-contrib
- I see this error on
stack exec yesod-rest
:
yesod-rest: libpq: failed (FATAL: password authentication failed for user "postgres"
FATAL: password authentication failed for user "postgres")
- I see this error on
stack exec yesod-rest
:
yesod-rest: libpq: failed (FATAL: database "test" does not exist)
Create a database named test
on your postgres server.
- The
webpack
program is automatically getting closed.
Try running this command:
echo fs.inotify.max_user_watches=524288 | sudo tee -a /etc/sysctl.conf && sudo sysctl -p