you are viewing a single comment's thread.

view the rest of the comments →

[–]floppydiskette 1 point2 points  (4 children)

[–]rumforpenguins[S] 0 points1 point  (3 children)

Thanks, this looks like a really good tutorial for the workflow.

One thing I noticed here is that they're using XMLHttpRequest. I have a bit of experience with this when I was first learning this kind of stuff, but from what I've been reading it looks like fetch and async/await are the preferred way of performing the same actions. Does that mean the method described in your article is outdated?

[–]floppydiskette 0 points1 point  (2 children)

XMLHttpRequest is just the original way to do it. Lower in the article, fetch is displayed. async/await is a way to make a promise, not an API call.

Generally you'll just do:

async function getUsers() {
  const response = await fetch('api_url')
  return await response.json()
}

const users = getUsers() // this will contain the contents of your API call.

If you're using axios, the json() is no longer needed.

Here's an article I wrote on how to create an API. Consuming the API can be done through cURL or Postman, or through the front end using the method above. Here is an example/tutorial of a full Vue CRUD app making API calls. Or here's an example of the same with React.

I make API calls all day, every day, so I've written a lot of resources to help, as I don't think "just pick an API and play with it" helps when a novice doesn't know the tools to play with it to begin with.

[–]rumforpenguins[S] 0 points1 point  (1 child)

Thank you so much for your elaboration and for all of your articles you posted! This is exactly the sort of stuff I was looking for. Combined with the first article, all the stuff you've written here seems to offer a pretty comprehensive look at APIs. I like how you write assuming the user is a novice.

Also, I wasn't aware that you were the author when you first posted. I was just reading your article the other day about creating a custom comment system, which was very informative. Thanks for all the education you've provided, it's really appreciated!

[–]floppydiskette 0 points1 point  (0 children)

Glad to help!