7 stable releases
Uses new Rust 2024
new 1.1.5 | May 20, 2025 |
---|---|
1.1.3 | May 19, 2025 |
1.0.2 | May 18, 2025 |
#965 in Command line utilities
358 downloads per month
89KB
2.5K
SLoC
NeoCurl
A command line tool to test servers.
Features
- Sending requests
- Running definintions at runtime
- Tests
- Logs
- Json support
- Custom library loading
Install
Make sure you have rust installed.
Install using cargo install neocurl
.
Now neocurl
and ncurl
commands should be available.
Usage
- Create a new file (default name is
neocurl.lua
) - Add request definitions. Example:
define({
name = "get_request",
func = function()
result = send({
url = "https://httpbin.org/get",
method = "GET",
headers = {
["User-Agent"] = "Neocurl",
["Accept"] = "application/json"
},
})
print_response(result)
end,
})
- Run via
ncurl run get_request
Advaced
Use helpers, tests, runs, and async.
define({
name = "get_request",
func = function()
-- Helper function to get and format currnet timestamp
now = format_time("%Y-%m-%d %H:%M:%S")
result = send({
url = "https://httpbin.org/get",
method = "GET",
headers = {
["User-Agent"] = "Neocurl",
["Accept"] = "application/json",
["X-Time"] = now
},
})
print_response(result)
-- Test for result
assert("200 status", result.status == 200)
assert_not("status >= 400", result.status >= 400)
end,
})
define({
name = "run_get_request",
func = function()
-- Run a definition and runtime twice
run("get_request", 2)
end,
})
define({
name = "async",
func = function()
-- Run definitions and runtime using async.
run_async({"get_request", "run_get_request"}, 10)
end,
})
Guide
Args
--file
or-f
and<string>
: Set the file path. Default isneocurl.lua
. Ex.neocurl -f ncurl_custom_file.lua
- Commands:
list
: List all definitions from the file.run
and<name>
: Run a definition from the file.repl
: Run REPL.
Functions
Definitions
define(name, func)
: Func is executed when a definition is called by its name.
Runs
run(name, Option<amount>)
: Run a definition by name. Optional amount specifies the amount of subsequent calls, default is 1.run_async(names, Option<amount>, Option<delay>)
: Run a definitions specified in the names table (Ex.{"run1", "run2"}
). Optionalamount
specifies the amount of subsequent calls, default is 1. Optionaldelay
specifies delay between async calls in milliseconds, default is 100ms (if set too low, unexpected behaivor might occur as the amount of threads is not limited).
Log
debug(message)
: Logmessage
with debug level.info(message)
: Logmessage
with info level.warn(message)
: Logmessage
with warn level.error(message)
: Logmessage
with error level.
Test
If any test fails in run
command, the tool will exit with exit code of 1
(Use in CI/CD? :D).
assert(message, condition)
: Asserts thatcondition
istrue
, logs withmessage
.assert_not(message, condition)
: Asserts thatcondition
isfalse
, logs withmessage
.assert_eq(message, left, right)
: Asserts thatleft
is equal toright
, logs withmessage
.assert_ne(message, left, right)
: Asserts thatleft
is not equal toright
, logs withmessage
.
Helpers
time
: Returns timestamp in millis since the epoch.format_time(format_str)
: Returns time formatted using format_str. Ex.format_time("%Y-%m-%d %H:%M:%S")
to_base64(payload)
: Encodespayload
in base64.from_base64(base64)
: Decodes from base64dump(value)
: Dumpsvalue
to a string and returns it. Useful for debugging tables. Ex.print(dump(tbl))
Import
import(path)
: Returns code loaded from a lua file located atpath
. Ex.yaml = import("yaml_lib.lua")
Built-in Libs
Json
dkjson is used to encode/decode json. Example usage:
define({
name = "json",
func = function()
json = require("json")
local tbl = {
animals = { "dog", "cat", "aardvark" },
instruments = { "violin", "trombone", "theremin" },
bugs = json.null,
trees = nil
}
local str = json.encode(tbl, { indent = false })
print(str)
end,
})
Dependencies
~16–30MB
~457K SLoC