@aryarte/yapijs v1.0.6
YAPIJS
a simple tool for testing your REST API and this tool is made with JS
USAGE
before use you must be install this tool by type
npm i @aryarte/yapijs
then, let's create a simple yapi.conf
URL localhost:8888
$Request login
Method get
Route /login
and save it to yapi.conf
npm script
you can add a npm script on package.json.
"scripts": {
"apiTest": "yapijs"
},
you can call it on console/terminal, you have to call on the path of yapi.conf
npm run apiTest
Import
other way to run yapijs, you can import it to your index.js and run as a callback in app.listen
import {start} from "@aryarte/yapijs"
...
//somecode
app.listen(PORT,()=>{
start()
})
YAPI Config
yapiConf is a file which required by yapijs to work fine, manage your request on it
URL
url is requried on a request
URL localhost:8888
PRODUCTION
use this on top your config to tell yapijs your project on production
$PRODUCTION
to disabled only add "#" on the front
#$PRODUCTION
LOG
two option you can show the or not. but log still write on yapi.log
to show
LOG true
to hide
LOG false
Request
you can use this to make a request define by name
$Request <name>
if name empty, yapijs will make a random name for it
Request Field
- Route
route to add a endpoint to your url. it's requried
$Request login
Route /login
- Method
to define what method want to use. method does not provide a default value, you have to fill it, use lowercase.
$Request login
Route /login
Method get
- Header and EndHeader
to add your request a header. the header data must be a json stringify format.
$Request login
Route /login
Method get
Header
{"authorization":"Bearer aslaljsc..."}
EndHeader
you have to add a EndHeader after header data.
- Body and EndBody
on the body we have 3 option. String, Json, and File
to send JSON on JSON stringify format
...
Body json
{"name":"komang"}
EndBody
to send a String
...
Body string
hi my name is akkun
EndBody
to send a File
...
Body file
./path/to/your/file
EndBody
remember to add EndBody after body's data.
- Response
you can add a responses to config field
Response as data
it will be save response to config.data
REF
you can use value of a config field
Header
{"authorization":"$REF(token)"}
EndHeader
it will be replace $REF(token) with config.token. if config.token undefined the $REF(token) not replace
Config Example
#$PRODUCTION
URL localhost:8888
LOG true
$Request
Route /login
Method post
Header
{"authorization" : "true"}
EndHeader
Body json
{
"fullname": "komang",
"username": "ary",
"password": "komang",
"email" : "komang@gmail.com",
"confirmPassword": "$REF(url)"
}
EndBody
Response as ayank
$Request login
Route /login
Method get
Header
{
"Authorization":"Bearer[space]$REF(ayank.token)"
}
EndHeader
$Request te
Route /
Method post
Body file
./yapi.log
EndBody