Closed juancarlospaco closed 3 years ago
Name: HTTP Harpoon
Author: Juan
Posting:
HttpClient
strictFuncs
Uri
GET
POST
downloadFile
openArray
const
isIpv6: bool
HttpMethod
HttpCode
Socket
get()
post()
runnableExamples
doAssert
Examples require to import harpoon and uri.
harpoon
uri
echo getContent(parseUri"http://httpbin.org/get") echo postContent(parseUri"http://httpbin.org/post", "data here")
import std/json let jsonData: JsonNode = %*{"key": "value", "other": 42} doAssert getJson(parseUri"http://httpbin.org/get") is JsonNode doAssert postJson(parseUri"http://httpbin.org/post", jsonData) is JsonNode
downloadFile(parseUri"http://httpbin.org/image/png", "temp.png") downloadFile([(url: parseUri"http://httpbin.org/image/png", path: "temp.png"), (url: parseUri"http://httpbin.org/image/jpg", path: "temp.jpg")])
const header = newDefaultHeaders("body", "application/json", "application/json") # Use std/sequtils to manipulate the header or something...
import std/asyncdispatch proc example() {.async.} = doAssert getContent("http://httpbin.org/get") is Future[string] doAssert deleteContent("http://httpbin.org/delete") is Future[string] doAssert putContent("http://httpbin.org/put", "data here") is Future[string] doAssert postContent("http://httpbin.org/post", "data here") is Future[string] doAssert patchContent("http://httpbin.org/patch", "data here") is Future[string] doAssert downloadFile("http://httpbin.org/image/png", "temp.png") is Future[void] waitFor example()
echo deleteContent(parseUri"http://httpbin.org/delete") echo putContent(parseUri"http://httpbin.org/put", "data here") echo patchContent(parseUri"http://httpbin.org/patch", "data here")
Due to only having a single submission this will be held until more projects, just for more quantity.
Name: HTTP Harpoon
Author: Juan
Posting:
HttpClient
.strictFuncs
.Uri
type for URL.GET
andPOST
from JSON to JSON directly.downloadFile
that takesopenArray
of URLs.const
.isIpv6: bool
attribute.HttpMethod
enum, not strings. Status code useHttpCode
not integers.Socket
with multiple clients, reuseSocket
.get()
orpost()
.runnableExamples
withdoAssert
for everything.GET and POST
Examples require to import
harpoon
anduri
.GET and POST from JsonNode to JsonNode
Download files
HTTP Headers can be const
Async
PUT, DELETE, etc