Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
H
hikaru
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
TO
hikaru
Commits
3b8108dd
Verified
Commit
3b8108dd
authored
4 years ago
by
jan.hamal.dvorak
Browse files
Options
Downloads
Patches
Plain Diff
Add a shortcut for route declaration
Signed-off-by:
Jan Hamal Dvořák
<
mordae@anilinux.org
>
parent
420c0c59
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
lib/Hikaru/Route.hs
+8
-0
8 additions, 0 deletions
lib/Hikaru/Route.hs
test/Hikaru/Demo.hs
+14
-7
14 additions, 7 deletions
test/Hikaru/Demo.hs
with
22 additions
and
7 deletions
lib/Hikaru/Route.hs
+
8
−
0
View file @
3b8108dd
...
@@ -19,6 +19,7 @@ module Hikaru.Route
...
@@ -19,6 +19,7 @@ module Hikaru.Route
-- ** Path Matching
-- ** Path Matching
,
seg
,
seg
,
(
</
)
,
arg
,
arg
,
argWith
,
argWith
,
rest
,
rest
...
@@ -228,6 +229,13 @@ where
...
@@ -228,6 +229,13 @@ where
else
Nothing
else
Nothing
-- |
-- Shortcut to append a path segment in a more readable way.
--
(
</
)
::
Route
a
->
Text
->
Route
a
(
</
)
r
t
=
r
<*
seg
t
-- |
-- |
-- Match, parse and return following path segment.
-- Match, parse and return following path segment.
--
--
...
...
This diff is collapsed.
Click to expand it.
test/Hikaru/Demo.hs
+
14
−
7
View file @
3b8108dd
...
@@ -105,7 +105,7 @@ where
...
@@ -105,7 +105,7 @@ where
runAction
::
ModelEnv
->
Action
()
->
Application
runAction
::
ModelEnv
->
Action
()
->
Application
runAction
me
act
=
do
runAction
me
act
=
do
respond
$
\
ae
->
do
respond
\
ae
->
do
runReaderT
(
unAction
act
)
(
DemoEnv
ae
me
)
runReaderT
(
unAction
act
)
(
DemoEnv
ae
me
)
...
@@ -115,23 +115,30 @@ where
...
@@ -115,23 +115,30 @@ where
-- Register nicer 404 error handler.
-- Register nicer 404 error handler.
handler
NotFound
handleNotFound
handler
NotFound
handleNotFound
-- Read configuration from environment.
wrapActions
(
updateConfigFromEnv
>>
)
-- Negotiate content for the root page.
-- Negotiate content for the root page.
route
$
getRootHtmlR
<$
get
<*
offerHTML
route
$
getRootHtmlR
<$
get
<*
offerHTML
route
$
getRootTextR
<$
get
<*
offerText
route
$
getRootTextR
<$
get
<*
offerText
-- Disable caching for
all the following
endpoints
.
-- Disable caching for
these
endpoints
:
wrapAction
(
defaultHeader
hCacheControl
"no-store"
>>
)
do
wrapAction
(
defaultHeader
hCacheControl
"no-store"
>>
)
do
-- Present a simple greeting page.
-- Present a simple greeting page.
route
$
getHelloR
<$
get
<
*
seg
"hello"
<*>
arg
route
$
getHelloR
<$
get
<
/
"hello"
<*>
arg
<*
offerText
<*
offerText
-- Present an echoing JSON API.
-- Present an echoing JSON API.
route
$
postEchoR
<$
post
<
*
seg
"api"
<
*
seg
"echo"
route
$
postEchoR
<$
post
<
/
"api"
<
/
"echo"
<*
offerJSON
<*
acceptJSON
<*
offerJSON
<*
acceptJSON
-- Case handling.
-- Handle new cases.
route
$
postCaseR
<$
post
<*
seg
"case"
<*
seg
""
<*
acceptForm
route
$
postCaseR
<$
post
</
"case"
</
""
route
$
getCasesR
<$
get
<*
seg
"case"
<*
seg
""
<*
offerJSON
<*
acceptForm
-- Handle case listing.
route
$
getCasesR
<$
get
</
"case"
</
""
<*
offerJSON
-- Handlers ----------------------------------------------------------------
-- Handlers ----------------------------------------------------------------
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment