No description
Find a file
dependabot[bot] e5727c7b1c
Bump actions/checkout from 5 to 6 (#37)
Bumps [actions/checkout](https://github.com/actions/checkout) from 5 to 6.
- [Release notes](https://github.com/actions/checkout/releases)
- [Changelog](https://github.com/actions/checkout/blob/main/CHANGELOG.md)
- [Commits](https://github.com/actions/checkout/compare/v5...v6)

---
updated-dependencies:
- dependency-name: actions/checkout
  dependency-version: '6'
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2025-12-01 08:29:34 +03:00
.github Bump actions/checkout from 5 to 6 (#37) 2025-12-01 08:29:34 +03:00
examples Files (#27) 2024-08-21 08:21:45 +03:00
src Allow simultaneous usage of files and streamingFiles (#34) 2025-02-26 12:15:51 +03:00
tests Allow simultaneous usage of files and streamingFiles (#34) 2025-02-26 12:15:51 +03:00
.gitattributes Initial commit 2023-11-19 22:26:14 +03:00
.gitignore Parse response body as HTML (#12) 2024-02-15 16:45:54 +03:00
LICENSE Initial commit 2023-11-19 22:26:14 +03:00
README.md Files (#27) 2024-08-21 08:21:45 +03:00
yahttp.nimble Files (#27) 2024-08-21 08:21:45 +03:00

yahttp - Awesome simple HTTP client for Nim

GitHub Release CI

  • Based on Nim std/httpclient
  • No additional dependencies
  • API focused on DX

Installation

nimble install yahttp

Examples

more examples here

Get HTTP status code

import yahttp

echo get("https://www.google.com/").status

Send query params and parse response to JSON

import json
import yahttp

let laptopsJson = get("https://dummyjson.com/products/search", query = {"q": "Laptop"}).json()
echo laptopsJson["products"][0]["title"].getStr()

API

Method procedures

get("http://api")
put("http://api")
post("http://api")
patch("http://api")
delete("http://api")
head("http://api")
options("http://api")

Arguments:

  • url - request URL. The only required argument
  • headers - request HTTP headers. Example: {"header1": "val", "header2": "val2"}
  • query - request query params. Example: {"param1": "val", "param2": "val2"}
  • encodeQueryParams - parameters for encodeQuery function that encodes query params. More
  • body - request body as a string. Example: "{\"key\": \"value\"}". Is not available for get, head and options procedures
  • files - array of files to upload. Every file is a tuple of multipart name, file name, content type and content
  • sreamingFiles - array of files to stream from disc and upload. Every file is a tuple of multipart name and file path
  • auth - login and password for basic authorization. Example: ("login", "password")
  • timeout - stop waiting for a response after a given number of milliseconds. -1 for no timeout, which is default value
  • ignoreSsl - no certificate verification if true
  • sslContext - SSL context for TLS/SSL connections. See newContext

General procedure

request("http://api")

Has the same arguments as method procedures and one additional:

  • httpMethod - HTTP method. Method.GET by default. Example: Method.POST

Response object

All procedures above return Response object with fields:

  • status - HTTP status code
  • body - response body as a string
  • headers - table, where keys are header keys and values are sequences of header values for a key
  • request - object with request data processed by yahttp
    • url - stores full url with query params
    • headers - stores HTTP headers with Authorization for basic authorization
    • httpMethod - HTTP method
    • body - request body as a string

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
  • Response.raiseForStatus() - throws HttpError exceptions if status is 400 or above

Other helper functions

object.toJsonString() - converts object of any type to json string. Helpful to use for body argument