| CARVIEW |
Select Language
HTTP/1.1 200 OK
Connection: keep-alive
Server: nginx/1.24.0 (Ubuntu)
Content-Type: text/html; charset=utf-8
Cache-Control: public, max-age=300
Content-Encoding: gzip
Via: 1.1 varnish, 1.1 varnish
Accept-Ranges: bytes
Age: 0
Date: Mon, 19 Jan 2026 02:31:21 GMT
X-Served-By: cache-dfw-kdfw8210105-DFW, cache-bom-vanm7210054-BOM
X-Cache: MISS, MISS
X-Cache-Hits: 0, 0
X-Timer: S1768789882.518726,VS0,VE329
Vary: Accept, Accept-Encoding
transfer-encoding: chunked
yesod-filter: Automatic filter generator for Yesod
yesod-filter: Automatic filter generator for Yesod
Downloads
- yesod-filter-0.1.0.2.tar.gz [browse] (Cabal source package)
- Package description (as included in the package)
Maintainer's Corner
For package maintainers and hackage trustees
Candidates
| Versions [RSS] | 0.1.0.0, 0.1.0.1, 0.1.0.2 |
|---|---|
| Change log | ChangeLog.md |
| Dependencies | base (>=4.7 && <5), persistent, template-haskell, text (>=1.2.4), time (>=1.9), yesod-core, yesod-persistent [details] |
| License | BSD-3-Clause |
| Copyright | IIJ Innovation Institute Inc. |
| Author | Kenzo Yotsuya |
| Maintainer | kyotsuya@iij-ii.co.jp |
| Uploaded | by KenzoYotsuya at 2020-10-08T08:22:41Z |
| Category | Web |
| Home page | https://github.com/iij-ii/yesod-filter#readme |
| Source repo | head: git clone https://github.com/iij-ii/yesod-filter |
| Distributions | |
| Downloads | 478 total (11 in the last 30 days) |
| Rating | (no votes yet) [estimated by Bayesian average] |
| Your Rating |
|
| Status | Docs available [build log] Last success reported on 2020-10-08 [all 1 reports] |
Readme for yesod-filter-0.1.0.2
[back to package description]yesod-filter
yesod-filter is a library that automatically generates Filter and SelectOpt from URL query string. yesod-filter is inspired by django-filter.
Usage
Example
{-
# Suppose the model is defined as follows:
Pet json
name Text
age Int
deriving Eq
deriving Show
# And the route is defined as follows:
/pets PetsR GET
-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE TemplateHaskell #-}
module Handler.Pet where
import Import
import Yesod.Filter.TH
-- Define the query options to be available.
$(mkFilterGenerator "Pet" defaultOptions
{ filtering = defaultFiltering
{ filterDefs =
[ FilterDef "name" defaultFilterParams
, FilterDef "age" defaultFilterParams
]
}
, sorting = defaultSorting
{ sortFields = ["name", "age"]
, defaultOrdering = ORDERBY "id" ASC
}
}
)
getPetsR :: Handler Value
getPetsR = do
-- The list of Filter and SelectOpts are automatically converted from query parameters.
filters' <- $(mkFilters)
selectOpts <- $(mkSelectOpts)
pets <- runDB $ selectList filters' selectOpts
returnJson pets
The above handler definition generates the following endpoint.
# Without query strings
$ curl -s "https://localhost:3000/pets" | jq .
[
{
"age": 5,
"name": "John",
"id": 1
},
{
"age": 3,
"name": "Charlie",
"id": 2
},
{
"age": 10,
"name": "Jack",
"id": 3
}
]
# Filter: WHERE AGE > 3
$ curl -s "https://localhost:3000/pets?age__gt=3" | jq .
[
{
"age": 5,
"name": "John",
"id": 1
},
{
"age": 10,
"name": "Jack",
"id": 3
}
]
# SelectOpt: ORDER BY name
$ curl -s "https://localhost:3000/pets?sort=name" | jq .
[
{
"age": 3,
"name": "Charlie",
"id": 2
},
{
"age": 10,
"name": "Jack",
"id": 3
},
{
"age": 5,
"name": "John",
"id": 1
}
]
LICENCE
Copyright (c) IIJ Innovation Institute Inc.
Licensed under The 3-Clause BSD License.