Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/mmhelloworld/fregelet
A basic web framework for Frege on top of servlet
https://github.com/mmhelloworld/fregelet
Last synced: about 1 month ago
JSON representation
A basic web framework for Frege on top of servlet
- Host: GitHub
- URL: https://github.com/mmhelloworld/fregelet
- Owner: mmhelloworld
- License: bsd-3-clause
- Created: 2015-12-29T05:04:14.000Z (almost 9 years ago)
- Default Branch: master
- Last Pushed: 2016-10-28T03:54:03.000Z (about 8 years ago)
- Last Synced: 2024-02-13T04:39:06.607Z (10 months ago)
- Language: Frege
- Size: 8.79 KB
- Stars: 6
- Watchers: 2
- Forks: 0
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-frege - Fregelet - Frege web framework based on servlet. (Libraries / Web Frameworks)
README
# Fregelet
A very basic web framework for Frege on top of Servlet## Run via maven
1. `mvn install`
1. `mvn exec:exec`## Example
### Start server
```frege
config = ServerConfig {
port = 8080,routes = [
("/greet/:name", [Get, Post], greet),
("/date", [Get], date),
("/download", [Get], downloadCsv)
]
}main = startServer config
```To try it in your browser, go to:
http://0.0.0.0:8080/greet/Foo
### Send JSON
```frege
data Greeting = Greeting { message :: String }
instance ToJSON Greeting where
toJSON Greeting { message } = Struct [ assoc "message" message ]greet :: Handler ()
greet = do
name ← pathParam "name"
let greeting = Greeting $ "Hello, " ++ (fromMaybe "there" name)
sendJSON greeting```
### Send simple text
```frege
date :: Handler ()
date = liftIO (Date.new () >>= _.toString) >>= sendText```
### Write directly to response
```frege
downloadCsv :: Handler ()
downloadCsv = do
web ← Handler.ask
let response = web.response
csvData = "foo,bar,baz"
sendCsv = do
response.setContentType "text/csv"
response.setHeader "Content-Disposition" "attachment; fileName=output.csv"
response.write csvData
liftIO sendCsv```