Update example (#163)

* Moving from inquirer to prompts.

It has a smaller dependency graph and we don't need the fancy features
inquirer has.

* Added a single better example to keep updated as I finalize the schema.
This commit is contained in:
David Díaz 2020-11-21 21:59:03 -06:00 committed by GitHub
parent 987c1df81e
commit 849b823311
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 41 additions and 145 deletions

23
examples/beau.yml Normal file
View File

@ -0,0 +1,23 @@
endpoint: https://pokeapi.co/api/v2
# Try replacing this pokemon using params:
# beau request get-pokemon -P "pokemon=dragapult"
environment:
_:
pokemon: ditto
GET /pokemon/$env._.pokemon: get-pokemon
GET $get-pokemon.body.location_area_encounters: get-encounters
---
host: httpbin
endpoint: https://httpbin.org
POST /anything:
- alias: post-first-area
payload:
area: $get-encounters.body.0.location_area.name
- alias: post-pokemon-type
payload:
type: $get-pokemon.body.types.0.type.name

View File

@ -1,15 +0,0 @@
VERSION: 1
ENDPOINT: https://api.github.com
auth: &auth
HEADERS:
Authorization: token asfdasf123423sd1fgnh7d83n478
User-Agent: Beau
GET /user:
ALIAS: $user
<<: *auth
GET /user/repos:
ALIAS: $repos
<<: *auth

View File

@ -1,22 +0,0 @@
version: 1
endpoint: http://httpbin.org
environment:
the:
post: 2
defaults:
headers:
hello: 'Hello2'
POST /anything:
alias: anything
payload:
title: $jpa:get-post.body.title
---
host: jpa
endpoint: http://jsonplaceholder.typicode.com
GET /posts/$env.the.post: get-post
GET /users/$jpa:get-post.body.userId: hello

View File

@ -1,27 +0,0 @@
version: 1
endpoint: https://httpbin.org/
cookiejar: true
environment:
params:
name: David
GET /anything:
- alias: anything
payload:
name: $env.params.name
- alias: anything2
GET /cookies/set:
alias: set-cookies
params:
hello: World
GET /status/418:
alias: teapot
POST /post:
alias: post
formdata:
id: $[uuid()]
file: $[createReadStream('./github.yml')]

View File

@ -1,29 +0,0 @@
version: 1
endpoint: 'http://jsonplaceholder.typicode.com'
environment:
the:
post: 1
defaults:
headers:
hello: $posts.body.0.userId
GET /posts/$env.the.post: get-post
GET /posts/:
alias: posts
headers:
hello: false
POST /posts/:
alias: new-post
documentation:
title: New Post
GET /users/$posts.body.0.userId:
alias: post-user
documentation:
description: Fetches the user for a give post.
params:
hello: 'world'

View File

@ -1,11 +0,0 @@
endpoint: http://localhost:10080
plugins:
- jwt:
data:
userId: 12
name: Sergio
secret: 'asdfasdf+asdfasdf/asdfasdfasdfasdf=='
GET /test:
alias: test

View File

@ -1,37 +0,0 @@
VERSION: '1'
ENDPOINT: https://slack.com/api
auth: &auth
token: xoxp-139455775026-139455775090-147751461120-f224ed6ffee029869a0f138d0859e7d6
GET /users.getPresence:
ALIAS: presence
PARAMS:
<<: *auth
GET /channels.list:
ALIAS: channel-list
PARAMS:
<<: *auth
exclude_archived: true
GET /channels.info:
ALIAS: channel-info
PARAMS:
<<: *auth
channel: $channel-list.response.body.channels.0.id
POST /chat.postMessage:
ALIAS: new-message
PARAMS:
<<: *auth
channel: $channel-info.response.body.channel.id
text: 'Hey Seich!'
parse: full
link_names: true
username: Beau
GET /users.list:
ALIAS: user-list
PARAMS:
<<: *auth

View File

@ -71,6 +71,9 @@
"cookiejar": {
"type": "boolean"
},
"host": {
"type": "string"
},
"defaults": {
"$ref": "#/definitions/requestObject"
},
@ -83,7 +86,17 @@
]
}
},
"environment": {}
"environment": {
"type": "object",
"additionalProperties": true,
"properties": {
"_": {
"type": "object",
"description": "Environment variables brought in by cli params or dotenv.",
"additionalProperties": true
}
}
}
},
"patternProperties": {
"(GET|HEAD|POST|PUT|DELETE|CONNECT|OPTIONS|TRACE|PATCH)\\s.*": {

View File

@ -64,10 +64,8 @@ class Request {
}
async exec(cache = new RequestCache()) {
const isPathFullUrl = isUrl(this.PATH)
let settings = cache.parse({
baseUrl: isPathFullUrl ? '' : this.ENDPOINT,
baseUrl: '',
uri: this.PATH,
method: this.VERB,
jar: this.COOKIEJAR,
@ -83,6 +81,9 @@ class Request {
resolveWithFullResponse: true
})
const isPathFullUrl = isUrl(settings.uri)
settings.baseUrl = isPathFullUrl ? '' : this.ENDPOINT
settings = removeOptionalKeys(settings, [
'headers',
'qs',