Flexible REST API testing in Visual Studio Code using Simple Javascript Object. Just like writing JSON!
- Create HTTP request files with simple Javascript object (just like JSON)
- Send requests directly from VS Code
- Pretty response panel/tab view that match with current theme
- Build multiple requests in single file
- Import common files like json or another js
- Auto persist cookies
- Auto save last successful responses (200 status code)
- Auto import
*.rc.js
(common config files) - Load saved responses
- Get data from a response (eg. authentication bearer)
- Supports images, with viewable headers
- All features from Javascript for very complex request
The only requirements are to use specific file extensions.
*.req.js
- for request files*.rc.js
- for common request configuration files
No other requirements or installation!
Dead simple example, with just URL.
Write the following code inside mytodos.req.js
// Send Request
exports.get = 'http://jsonplaceholder.typicode.com/todos'
// Send Request
exports.post = {
url: 'http://jsonplaceholder.typicode.com/todos',
data: {
title: 'New Todo'
}
}
Click the Send Request
CodeLen above it. Or simply right click anyware inside editor and select Send Request
.
A response panel/tab view will auto show and give you complete information about the request.
Following are the options you can use to build the request.
// axios request config object
exports.post = {
url: 'https://jsonplaceholder.typicode.com/posts',
// Add custom headers
headers: {
'X-Custom-Header': 'This is a custom data'
},
// Add body data. Can also be string
data: {
title: 'Hello',
body: 'This is a body',
userId: 1
},
// Add query string parameters
params: {
foo: 'bar'
},
// Manual override method
method: 'PATCH'
}
Most common options you might need are:
url
- resource urlparams
- the query stringfoo=bar&page=1&offset=6
but in object formatdata
- the body of requestheaders
- request headersmethod
- GET, POST, PUT, PATCH, ...
Also check out axios request config object for more information.
A "Request Configuration" file holds the common data for all request files *.req.js
.
Once you execute a request file, it will look for any configuration file and import all the data.
File: _common.rc.js
exports.email = '[email protected]'
exports.password = 'ssshhh'
// Auto prepend to `url` in request file
exports.baseURL = 'https://myserver.com'
// Auto merge to request file
exports.headers = {
'X-Custom': 'Custom Data'
}
File: mytodos.req.js
exports.post = $ => ({
url: '/signin',
data: {
email: $('email'),
password: $('password')
}
})
/*
Will request to https://myserver.com/signin
with email, password and custom headers
*/
The $
value resolver. It resolve value from rc
files as well as from a response
.
// Resolve from `rc` file
$('email')
// Resolve from response
$('data.token', 'myserver.com/api/signin')
// Response structure
{
status: 200,
headers: { ... },
data: {
token: 'abc123'
}
}
Notes:
- Multiple rc files will be merged.
baseURL
will auto merge tourl
in req fileheaders
will also auto merge toheaders
in req file
rc
files can do many things but one common use case is authentication bearer.
// _auth.rc.js
module.exports = $ => {
var token = $('data.token', 'myserver.com/api/signin')
return {
headers: {
'Authorization': 'Bearer ' + token
}
}
}
// get-bearer.req.js
exports.post = {
url: 'myserver.com/api/signin',
data: { email, password }
}
// with-bearer.req.js
exports.get = {
url: '/protected/content'
}
Notice that /protected/content
will have Authorization
injected automatically.