Loading...
Loading...
This skill should be used when writing HTTP requests with the keq client library, building or registering keq middleware, configuring flow control, or working with KeqRequest instances. Triggers on: "import { request } from 'keq'", "keq HTTP request", "KeqRequest", "keq middleware", ".use()", ".flowControl()", ".get()", ".post()", ".resolveWith()", "keq onion model", "KeqMiddleware", "ctx.request", "ctx.response".
npx skill4agent add keq-request/skills keqnpm install keqkeq@keq-request/*import { request } from "keq"requestKeqRequestimport { KeqRequest } from "keq"
const api = new KeqRequest({ baseOrigin: "https://api.example.com" })await request.get(url)
await request.post(url)
await request.put(url)
await request.patch(url)
await request.delete(url)
await request.head(url)await request
.post("/cats/{catId}")
.params("catId", "123") // URI template params (RFC 6570)
.query({ breed: "british" }) // Query string
.set("Authorization", "Bearer t") // Headers
.send({ name: "mimi", age: 3 }) // JSON bodyawait request
.post("/upload")
.field("name", "mimi")
.attach("avatar", blob)const cat = await request.get<Cat>("/cats/1")const data = await request
.get("/x")
.resolveWith("json")
const text = await request
.get("/x")
.resolveWith("text")
const res = await request
.get("/x")
.resolveWith("response")
const blob = await request
.get("/x")
.resolveWith("blob")const stream = await request
.get("/events")
.resolveWith("sse")
for await (const event of stream) {
console.log(event.event, event.data)
}import { request, TimeoutException } from "keq"
await request
.get("/data")
.timeout(5000)
await request
.get("/data")
.retry(3, 1000)
await request
.get("/data")
.retry(5, (attempt) => Math.pow(2, attempt - 1) * 1000)import { KeqRequest } from "keq"
const parent = new KeqRequest({ baseOrigin: "https://api.example.com" })
const child = parent.fork() // Inherits parent middleware
child.inherit(parent) // Or: parent.adopt(child)fork()inherit()await next()import { KeqMiddleware } from "keq"
const auth: KeqMiddleware = async (ctx, next) => {
ctx.request.headers.set("Authorization", "Bearer token")
await next()
}
request.use(auth)request
.apply(auth)
.forRoutes({ host: "api.example.com" })
request
.apply(logger)
.exclude({ pathname: "/health" })
.forAllRoutes()references/middleware.md.flowControl()| Strategy | Behavior |
|---|---|
| Queue, execute one at a time |
| Limit parallel to N |
| Cancel previous pending request |
| Reject new if one is pending |
await request
.get("/search")
.query("q", value)
.flowControl("abort", "search")
await request
.get("/items")
.flowControl("concurrent", 5, "batch")references/flow-control.mdawait request
.get("/cats")
.retry(3)
.on("retry", ({ attempt }) => console.log(`Retry #${attempt}`))
.on("error", (err) => console.error(err))
.on("timeout", () => console.warn("Timed out"))const base = request
.get("/cats")
.set("Authorization", "Bearer t")
const [p1, p2] = await Promise.all([
base
.derive()
.query("page", 1),
base
.derive()
.query("page", 2),
])
request
.post("/analytics")
.send({ event: "view" })
.fire()references/request-building.mdreferences/middleware.mdreferences/flow-control.mdreferences/types.md