Skip to main content

ECMAScript Module (ESM))

This interactive playground demonstrates usage of the Lunex HTTP Client with modern ECMAScript Modules.

Edit the code below and send requests live to explore the client’s capabilities. Select the HTTP method to see and run example code live:

    // App.js
    import React, { useEffect, useState } from "react";
    import LunexClient, { LunexClientOptions } from "lunex-http";

    export default function App() {
      const [data, setData] = useState("");

      useEffect(() => {
        const client = new LunexClient(
          "https://jsonplaceholder.typicode.com",
          {},
          new LunexClientOptions({ timeout: 8000, maxRetries: 2 })
        );

        async function fetchData() {
          try {
            const result = await client.getAsync("users");
            setData(JSON.stringify(result, null, 2));
          } catch (error) {
            setData(`Error: ${error.message}`);
          }
        }

        fetchData();
      }, []);

      return <pre>{data}</pre>;
    }