ToolJet/docs/versioned_docs/version-2.33.0/how-to/use-axios.md
Aman Regu 72fa067550
[docs]: Update formatting for How To section (#9169)
* Updated the formatting of how to docs for the next and current versions

* Used the title cases in the heading

* Updated the formatting of how to docs for the next and current versions

* Used the title cases in the heading

* updated the formatting of inspector, form, cell colors

* resolved conflicts

* Updated the formatting of bulk update multiple rows, conditionaly format table, delete multiple rows, serverside pagination

* Updated access user groups, import external lib in js and python, use axios

* fix: border colour, blur

* Revert changes to versions.json

* Changed the formatting of how to docs

* add changes from docs/next to v2.34.0

* update: how to docs

* fix: image name create-new-query

* fix: image name import-successful.png

* fix: image name flatten-js

* fix: image name math-js-v2

* update: shorten page titles

---------

Co-authored-by: Asjad Ahmed Khan <iitasjad2001@gmail.com>
Co-authored-by: Karan Rathod <karan.altcampus@gmail.com>
2024-04-11 11:34:27 +05:30

2 KiB

id title
use-axios-in-runjs Use Axios in RunJS

ToolJet supports three libraries: Moment.js, Lodash, and Axios. This guide focuses on using the Axios library with RunJS queries. Axios is a promise-based HTTP client for making requests to your own or external servers. It supports various request types like GET, POST, PUT/PATCH, and DELETE.

GET Requests

We'll use JSONPlaceholder, a free API, to demonstrate GET and PUT requests.

  • Create a RunJS query and paste the code below:
var url = "https://jsonplaceholder.typicode.com/users/1";

var data = (await axios.get(url)).data;

return data

This code sets up a URL variable, makes a GET request to the API, and returns the data. Preview the query to see the API's response.

<img style={{ border:'0', marginBottom:'15px' }} className="screenshot-full" src="/img/how-to/use-axios/get.png" alt="Use Axios in RunJS"/>

POST Requests

  • Create a RunJS query and paste the code below:
var url = "https://jsonplaceholder.typicode.com/users";

var data = axios.post(url,{
  id: 11,
  name: "Shubhendra",
  username: "camelcaseguy",
  email: "shubhendra@tooljet.com",})

return data

This POST request sends user details to the server. The server's response, as shown below, includes Status: 201 indicating successful resource creation.

Use Axios in RunJS

To see Axios in action in a project, check out this tutorial: Build GitHub star history tracker.