Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

restlr

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

restlr - npm Package Compare versions

Comparing version 0.0.6 to 0.0.7

docs/_data/apis.yaml

18

.vscode/settings.json
{
"GitHubIssues.authToken": "d3bf2cff6ed8e7eb8c3c385f12e72d4be9c1e944",
"files.exclude": {

@@ -20,16 +21,5 @@ "**/.git": true,

],
"json.schemas": [
{
"fileMatch": [
"discover.json"
],
"url": "/siren.schema.json"
},
{
"fileMatch": [
"docs/_config.yaml"
],
"url": "jekyll"
}
]
"files.associations": {
"*.json": "liquid"
}
}
---
title: RESTlr - An interactive and true REST REPL for node.js
layout: default
---
# RESTlr
# RESTlr - Wrestling REST
> A wrestler for REST
Interactive and fun REPL for REST endpoint discovery written for node.js
## Features
* Easy navigation to links
* Auto following 201 `Location` HTTP header links
* Discovers `Link` headers and their `rel`
* Discovers `Location` headers in responses
* Optional auto following 201 `Location` HTTP header links
* Pluggable Hypermedia formats (supports SIREN hypermedia format for now only)
* (Partial) support for [GitHub REST API v3](https://developer.github.com/v3/)
<video src="assets/restlr.mp4" controls>
<p>Your browser doesn't support HTML5 video. Here is a <a href="assets/restlr.mp4">link to the video</a> instead.</p>
</video>
## Installation
> `npm i -g restlr`
## Usage
> `restlr <url>`
Like:
`restlr https://restlr.net/index.json`
`restlr https://api.github.com/users/pke/repos`
## Contribute
You have a nice REST Hypermedia API and want to showcase it?
Create a PR to add it to [docs/_data/apis.yaml](https://github.com/pke/restlr/tree/master/docs/_data/apis.yaml)
{
"name": "restlr",
"version": "0.0.6",
"version": "0.0.7",
"description": "A REST REPL for fun",
"repository": "pke/restlr",
"main": "src/index.js",
"main": "src/cli.js",
"scripts": {

@@ -12,3 +12,3 @@ "start": "src/cli.js",

},
"bin": "src/index.js",
"bin": "src/cli.js",
"keywords": [

@@ -15,0 +15,0 @@ "rest",

{
"name": "restlr-plugin-github",
"version": "1.0.0",
"description": "Transforms unstructured non-hypermedia GitHub responses to SIREN",
"description": "Transforms semi-sructured GitHub responses to SIREN",
"main": "index.js",

@@ -6,0 +6,0 @@ "scripts": {

@@ -5,9 +5,4 @@ #!/usr/bin/env node

const { prompt } = require("enquirer")
const ora = require("ora")
const parseLinkHeader = require("parse-link-header")
const handleRequestAction = require("./handleRequestAction")
const mapItems = require("./mapItems")
const resourcePrompt = require("./prompts/resourcePrompt")
const client = require("./client/client")
const cpromise = (promise, defaultResult) => {

@@ -28,79 +23,3 @@ let outerReject

const handlers = [
{
test: {
"content-type": "application/json",
"x-github-media-type": "github.v3; format=json"
},
handle(response) {
const { handleResponse } = require("../restlr-plugin-github")
return handleResponse(response)
}
}
]
function transformResponse(headers) {
for (let i=0; i<handlers.length; ++i) {
const handler = handlers[i]
if (Object.keys(handler.test).every(header => {
const value = headers[header] || ""
return value.match(handler.test[header])
})) {
return handler.handle
}
}
return (response) => response
}
async function handleRequestAction(request) {
const { method = "get", href, form, type } = request
const spinnerText = `${method.toUpperCase()} ${href}...`
const spinner = ora(spinnerText).start()
/*const stillTrying = cpromise(
waitp(3000,
spinnerText + " Still trying",
"yellow")
.then(([text, color]) => {
spinner.color = color
spinner.text = chalk[color](text)
}).catch(() => {})
)*/
try {
//await waitp(5000)
const response = await client[method.toLowerCase()](href, {
headers: {
"accept": type
},
form
})
//stillTrying.cancel()
spinner.succeed(`${method.toUpperCase()} ${href} ${response.statusCode} ${response.statusMessage}`)
//console.log(response.headers["content-type"])
if (response.statusCode === 201) {
return {
request: {
href: response.headers.location
}
}
} else {
const json = transformResponse(response.headers)(JSON.parse(response.body || "{}"))
console.log(mapItems(json.properties || {}, (value, key) => `${key}: ${value}`).join("\n"))
const headerLinks =
Object.values(parseLinkHeader(response.headers.link))
.map(({url:href, rel}) => ({
href,
rel: [rel]
}))
json.links = (json.links || []).concat(headerLinks)
return {
prompt: resourcePrompt(json, response.headers.location, request)
}
}
} catch (e) {
spinner.fail(e.message)
throw e
}
}
// https://pastebin.com/raw/B7KHJL4r

@@ -115,3 +34,3 @@

request: {
href: "https://api.github.com/users/pke/repos" // "https://restlr.net/discover.json" //"https://api.github.com/repos/pke/acts_as_bookable/forks"
href: "https://restlr.net/discover.json" //"https://api.github.com/users/pke/repos" "https://api.github.com/repos/pke/acts_as_bookable/forks"
}

@@ -118,0 +37,0 @@ }

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc