# Testing out REST API's

**URL:** <https://discourse.nodered.org/t/testing-out-rest-apis/55522>\
**Category:** FAQs\
**Created:** [21 December 2021 11:56 UTC](https://discourse.nodered.org/t/testing-out-rest-apis/55522 "2021-12-21T11:56:48Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![TotallyInformation](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/totallyinformation/32/31_2.png) [@TotallyInformation](https://discourse.nodered.org/u/TotallyInformation)\
**Post date:** [21 December 2021 11:56 UTC](https://discourse.nodered.org/t/testing-out-rest-apis/55522/1 "2021-12-21T11:56:48Z")

</div>

Node-RED is a useful tool for accessing remote REST API's and also for creating them.

In either case, it can be useful to be able to test the API's separate to Node-RED.

Here are my chosen tools - both use the Microsoft VSCode free code editor as the host for convenience.

- The REST Notebook extension: [Notebooks, Visual Studio Code style](https://code.visualstudio.com/blogs/2021/11/08/custom-notebooks?ocid=aid3021690)

- The REST Client extension: [REST Client - Visual Studio Marketplace](https://marketplace.visualstudio.com/items?itemName=humao.rest-client)

```auto
// Test uibuilder v3 admin API routes
//
// Using REST Client extension https://github.com/Huachao/vscode-restclient#rest-client

// File variables
@hostname = localhost
@port = 1880
@host = {{hostname}}:{{port}}
@redAdminPath = red
@uibPath = uibuilder
@uibAdminPath = admin
@contentType = application/json
@createdAt = {{$datetime iso8601}}
# Valid uibuilder instance URL
@url = test1

# @name Sample-Get
# Get something and return it
GET http://{{host}}/{{redAdminPath}}/{{uibPath}}/{{uibAdminPath}}/{{url}}?ping=pong
content-type: {{contentType}}

{
    "name": "sample GET",
    "time": "{{createdAt}}"
}

###

# @name Sample-Put
# Write file contents
PUT http://{{host}}/{{redAdminPath}}{{uibAdminPath}}/{{url}}
content-type: {{contentType}}

{
    "name": "sample PUT",
    "time": "{{createdAt}}"
}

###

# @name Sample-Post
# Create a new folder or file
POST http://{{host}}/{{redAdminPath}}{{uibAdminPath}}/{{url}}
content-type: {{contentType}}

{
    "name": "sample DELETE",
    "time": "{{createdAt}}"
}

###

# @name Sample-Delete
# Delete a folder or a file
DELETE http://{{host}}/{{redAdminPath}}{{uibAdminPath}}/{{url}}
content-type: {{contentType}}

{
    "name": "sample DELETE",
    "time": "{{createdAt}}"
}

###

# @name Instance-Info
# Returns an HTML page of info for the current instance of uibuilder
GET http://{{host}}/{{redAdminPath}}{{uibAdminPath}}/instance/{{url}}
content-type: {{contentType}}

{
    "cmd": "showinstancesettings",
    "time": "{{createdAt}}"
}

###

# @name List-All-User-Urls
# Returns json list of all ExpressJS routes on the user app
GET http://{{host}}/{{redAdminPath}}/{{uibPath}}/{{uibAdminPath}}/{{url}}
content-type: {{contentType}}

{
    "cmd": "listurls",
    "time": "{{createdAt}}"
}

// NOTES:
// - can send a file: `< filename.json` or (for processing variables): `<@ filename.json`
// - ExpressJS supported methods are here: https://expressjs.com/en/4x/api.html#app.METHOD

```

---

<div class="post-metadata">

**Author:** ![shrickus](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/shrickus/32/517_2.png) [@shrickus](https://discourse.nodered.org/u/shrickus)\
**Post date:** [21 December 2021 14:28 UTC](https://discourse.nodered.org/t/testing-out-rest-apis/55522/2 "2021-12-21T14:28:48Z")

</div>

Nice info, Julian -- and if you are familiar with using Postman, the [ThunderClient extension](https://marketplace.visualstudio.com/items?itemName=rangav.vscode-thunder-client) does the same things, but from within your VSCode session.

I like to keep each project/server in a Collections of API calls that follow a logical testing sequence (login, query, update, create, etc) that I can quickly click through to test end-to-end. Various outputs of one API call (e.g. the login access\_token) can be used by the next API call (e.g. add a Bearer token to the headers). And the call can be converted to curl or many other programming language constructs -- now if only it would output the JSON for a node-red `http request` node... hmmm 🤔

---

<div class="post-metadata">

**Author:** ![TotallyInformation](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/totallyinformation/32/31_2.png) [@TotallyInformation](https://discourse.nodered.org/u/TotallyInformation)\
**Post date:** [21 December 2021 14:42 UTC](https://discourse.nodered.org/t/testing-out-rest-apis/55522/3 "2021-12-21T14:42:47Z")

</div>

ThunderClient looks interesting - I note that REST Client was an inspiration for it. As it happens, I prefer the text format of REST client over a GUI for this use. And I don't need CURL at all with these tools. I only use CURL to test downloads.

I did used to use Postman but then I had a series of issues with it - can't remember the details now - and I gave up on it. I think I found it too bloated and far too complex for ordinary use.

The ability to keep your tests in a single file is ideal - so for uibuilder for example, I have a tests folder and I keep all of the tests shown in a single file in there. I can run individual tests from within the file. But I think the new notebook format may be even better, not yet had the chance to try it extensively though.

I've also started using Jupyter notebooks to collect ideas, code snippets, etc not only for Python but also JavaScript since you can run notebooks on different "kernels" - also really handy to keep everything together along with Markdown based documentation. I use the same for when I need to work out a transformation process on data that I might want to redo later. Running up a Jupyter server for that used to be a major pain but with VSCode, that is no longer needed. That also meant I could ditch Anaconda which is not only horribly complex but is also no longer free in some cases.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [20 January 2022 11:57 UTC](https://discourse.nodered.org/t/testing-out-rest-apis/55522/4 "2022-01-20T11:57:27Z")

</div>

This topic was automatically closed after 30 days. New replies are no longer allowed.
