Postman test for API Endpoints

Good Morning - I have seen references to API testing using Postman. There is another similar tool called RapidAPI and assume they both are used to test endpoints. However, as a non-programmer, I’m not sure what to do after receiving the 200 “success” status code. What are the next steps?

Both software programs allow you to generate JS code for the GET request. Should that code be copied to the Coda code, and if so, where? Is it best to copy and paste the response results into the Coda code using the template below? Is there a video - other than the generic YouTube GET request videos - that would show the steps to take the Postman responses and use them to manage the API GET requests in Coda? Thank you all, in advance. I appreciate your time!

Using the sunrise-sunset pack code, I have an inkling that we are testing this part of the code:

let url = coda.withQueryParams("https://api.sunrise-sunset.org/json", {
  lat: lat,
  lng: lng,
  date: formattedDate,
  formatted: 0,
});
let response = await context.fetcher.fetch({
  method: "GET",
  url: url,
});
let results = response.body.results;
return {
  daylight: results.day_length + " seconds",
  sunrise: results.sunrise,
  sunset: results.sunset,
};

},
});

1 Like

Hi @SIMG_ADMIN - Indeed, Postman is a popular tool used to test an API. I personally prefer Insomnia, but they both do the same thing. Specifically, they allow you to manually send a request to an API and see the raw response. Building a Pack is sort of like building a robot that solves a puzzle, and tools like Postman let you solve that puzzle by hand first so that you can better build that robot.

Postman is mostly used for learning how an API works, but there are some parts you can copy directly into your Pack. This is usually the request URL and/or body. For example, you can use Postman to try out different URLs or JSON bodies, and when you find the one you want you can bring that into your Pack. For example, consider this sample from the docs that shows how to send JSON:

let payload = {
  foo: "bar",
};
let response = await context.fetcher.fetch({
  method: "POST",
  url: "https://httpbin.org/post",
  headers: {
    "Content-Type": "application/json",
  },
  body: JSON.stringify(payload),
});

Once you have things working in Postman, you could copy your URL to the url field and your JSON body to the payload variable.

Often the harder part, and which Postman doesn’t help with as much directly, is figuring out what to do with the API response. Postman shows you the raw API response, but reaching into that response and pulling out the parts you want requires custom JavaScript code.

1 Like

Thank you Eric… your response is so very useful. :grinning:

1 Like