No description
Find a file
2024-11-13 11:07:17 -06:00
.github/workflows update yaml 2024-11-10 15:02:51 -06:00
src fix docs gen 2024-02-08 18:19:51 -06:00
tests f 2024-02-02 16:21:47 -06:00
.gitignore Initial commit 2022-12-16 17:49:11 -08:00
LICENSE started 2022-12-16 21:05:28 -06:00
README.md update readme 2024-01-30 23:33:53 -06:00
webby.nimble 0.2.1 2024-02-05 02:21:11 -06:00

Webby

nimble install webby

Github Actions

API reference

This library has no dependencies other than the Nim standard library.

Webby is a collection of common HTTP data structures and functionality. This includes things like Url, HttpHeaders and QueryParams.

URL

  foo://admin:hunter1@example.com:8042/over/there?name=ferret#nose
  \_/   \___/ \_____/ \_________/ \__/\_________/ \_________/ \__/
   |      |       |       |        |       |          |         |
scheme username password hostname port   path       query   fragment

Use parseUrl to parse a URL:

let url = parseUrl("foo://admin:hunter1@example.com:8042/over/there?name=ferret#nose")
url.scheme == "foo"
url.username == "admin"
url.password == "hunter1"
url.hostname == "example.com"
url.port == "8042"
url.path == "/over/there"
url.query["name"] == "ferret"
url.fragment == "nose"

Note that the Url fields are stored in decoded form: /%6E%69%6D becomes /nim.

HTTP headers

Create a collection of HTTP headers:

var headers: HttpHeaders
headers["Content-Type"] = "image/png"

Check if a header is present:

if "Content-Encoding" in headers:
  echo headers["Content-Encoding"]

Iterate over the key-value pairs of headers:

for (k, v) in headers:
  echo k, ": ", v

Entries are stored in the order they are added. Procs like in, [] and []= are NOT case sensitive.

Query parameters

Parse a form-encoded string:

let
  search = "name=ferret&age=12&leg=1&leg=2&leg=3&leg=4"
  params = parseSearch(search)

Create a collection of query parameters:

var params: QueryParams
params["hash"] = "17c6d60"

Check if a parameter is present:

if "hash" in params:
  echo params["hash"]

Iterate over the query parameters:

for (k, v) in params:
  echo k, ": ", v

Entries are stored in the order they are added. Procs like in, [] and []= are case sensitive.

Repos using Webby

Some libraries using Webby include Mummy, Puppy and Curly.