10000 GitHub - treeform/webby: Web utilities - HTTP headers, query parsing etc
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content
/ webby Public
generated from treeform/nimtemplate

Web utilities - HTTP headers, query parsing etc

License

Notifications You must be signed in to change notification settings

treeform/webby

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

74 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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.

About

Web utilities - HTTP headers, query parsing etc

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

0