Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/justinwoo/purescript-ochadzuke
A library that combines Simple-JSON, Milkis (Fetch), and Chirashi (Error subtypes).
https://github.com/justinwoo/purescript-ochadzuke
chirashi milkis purescript simple-json
Last synced: 10 days ago
JSON representation
A library that combines Simple-JSON, Milkis (Fetch), and Chirashi (Error subtypes).
- Host: GitHub
- URL: https://github.com/justinwoo/purescript-ochadzuke
- Owner: justinwoo
- License: mit
- Created: 2018-10-03T21:14:16.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2018-10-03T21:14:55.000Z (about 6 years ago)
- Last Synced: 2024-10-11T04:39:19.668Z (about 1 month ago)
- Topics: chirashi, milkis, purescript, simple-json
- Language: PureScript
- Homepage:
- Size: 2.93 KB
- Stars: 7
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Purescript-Ochadzuke
A library that combines Simple-JSON, [Milkis](https://github.com/justinwoo/purescript-milkis) (Fetch), and [Chirashi](https://github.com/justinwoo/purescript-chirashi) (Error subtypes).
It's ochadzuke made by mixing Chirashi and Milkis.
![](https://i.imgur.com/sUeJgfi.png)
## Usage
```purs
main :: Effect Unit
main = Aff.launchAff_ do-- works normally
normal <- fetch' testUrl O.defaultFetchOptions'
assertEqual'
{ expected: { "userId": 1 }
, actual: normal
}-- gives an error in readForeign on mismatched decoding type
wrong <- Aff.attempt $ fetch' testUrl O.defaultFetchOptions'
case wrong of
Left e
| Just (variant :: O.Error) <- C.readVariant e
, Just multipleErrors <- V.prj O.readForeignS variant -> do
pure unit
Right (e :: { asdf :: String }) -> Aff.throwError $ Aff.error "False parsing result"
Left e ->
Aff.throwError e-- gives an error in otherS on random other failure
wrong2 <- Aff.attempt $ fetch' (M.URL "sdflsjdfasdf") O.defaultFetchOptions'
case wrong2 of
Left e
| Just (variant :: O.Error) <- C.readVariant e
, Just other <- V.prj O.otherS variant ->
assertEqual'
{ expected: "TypeError: Only absolute URLs are supported"
, actual: Aff.message other
}
Right (e :: {}) -> Aff.throwError $ Aff.error "False parsing result"
Left e -> Aff.throwError e
```See the [API Docs](https://pursuit.purescript.org/packages/purescript-ochadzuke/) or the [tests](test/Main.purs) for usage.