
Security News
Meet Socket at Black Hat and DEF CON 2025 in Las Vegas
Meet Socket at Black Hat & DEF CON 2025 for 1:1s, insider security talks at Allegiant Stadium, and a private dinner with top minds in software supply chain security.
an opinionated client for interacting with JSON rest endpoints
npm i --save-dev kno-rest
This client has several opinions, and was initially built for quickly working with rails JSON apis that I often end up building. The conventions it follows work well with my workflow, but your mileage may vary.
As an example of this, see the src/default_headers.js
file where you'll see
that all the rest calls include the X-CSRF-Token
header which is plucked from
the rails page on which the application lives. Also, we always set the Accept
header to application/json
Create a new instance and call a crud endpoint:
cont ENDPOINT = "/api/v1/messages"
async function getMessages() {
let messageService = new KRest(ENDPOINT)
let messages = await messagesService.index() // makes a GET call to endpoint
return messages
}
index
Run a GET call against endpoint:
kRest.index()
create
Run a POST call against endpoint:
kRest.create({message: {title: "hi", user_id: 3}})
show
Run a GET call against member route of endpoint with an id
kRest.show(45)
update
Run a PUT call against member route of endpoint with an id
let message = {id: 45, title:"hello", user_id: 3}
kRest.update(message.id, {message})
destroy
Run a DELETE call against member route of endpoint with an id
kRest.destroy(45)
returns true
if call was successful, false
if not
The above methods all take advantage of two methods on the kno-rest object.
collection
and member
. Using them you can buildup endpoint urls and execute
ajax calls to non-standard REST endpoints as well
For example assume you have typical REST crud stuff for a Foo at /api/v1/foo
,
but you also have a member route at /api/v1/foo/:id/bars
. You can use the
member
method to hit it with various method requests.
let ENDPOINT = "/api/v1/foo"
krest = new KnoRest(ENDPOINT)
let bar = {name: 'baz'}
kRest.member('POST', 32, {bar}, 'bar')
// sends POST to '/api/v1/foo/32/bar' with the {bar} object
Same for collection routes:
let ENDPOINT = "/api/v1/foo"
krest = new KnoRest(ENDPOINT)
krest.collection('GET', {from: '7d', to: '2d'}, 'sort')
// calls GET on /api/v1/foo/sort with the from and to params
FAQs
simple rest client helper
The npm package kno-rest receives a total of 1 weekly downloads. As such, kno-rest popularity was classified as not popular.
We found that kno-rest demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Meet Socket at Black Hat & DEF CON 2025 for 1:1s, insider security talks at Allegiant Stadium, and a private dinner with top minds in software supply chain security.
Security News
CAI is a new open source AI framework that automates penetration testing tasks like scanning and exploitation up to 3,600× faster than humans.
Security News
Deno 2.4 brings back bundling, improves dependency updates and telemetry, and makes the runtime more practical for real-world JavaScript projects.