Skip to content

Commit

Permalink
Parse response body as HTML (#12)
Browse files Browse the repository at this point in the history
* add html proc

* bump version
  • Loading branch information
mishankov authored Feb 15, 2024
1 parent fdc97a6 commit 4494eed
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 2 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,5 @@ nim.cfg

testresults/
testresults.html

test_yahttp
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,5 +76,6 @@ All procedures above return `Response` object with fields:

`Response` object has some helper procedures:
- `Response.json()` - returns response body as JSON
- `Response.html()` - returns response body as HTML
- `Response.to(t)` - converts response body to JSON and unmarshals it to type `t`
- `Response.ok()` - returns `true` if `status` is greater than 0 and less than 400
6 changes: 5 additions & 1 deletion src/yahttp.nim
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import base64, httpclient, net, json, uri, strutils, tables
import base64, httpclient, net, json, uri, strutils, tables, htmlparser, xmltree

import yahttp/internal/utils
import yahttp/exceptions
Expand Down Expand Up @@ -56,6 +56,10 @@ proc json*(response: Response): JsonNode =
## Parses response body to json
return parseJson(response.body)

proc html*(response: Response): XmlNode =
## Parses response body to html
return parseHtml(response.body)

proc to*[T](response: Response, t: typedesc[T]): T =
## Parses response body to json and then casts it to passed type
return to(response.json(), t)
Expand Down
2 changes: 1 addition & 1 deletion yahttp.nimble
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Package

version = "0.9.1"
version = "0.10.0"
author = "Denis Mishankov"
description = "Awesome simple HTTP client"
license = "MIT"
Expand Down

0 comments on commit 4494eed

Please sign in to comment.