Building app with API

I need to build an app that takes a rest api and displays different information depending on what people select. The trouble is I’ve never worked with JavaScript API’s before (I’ve only ever used PHP) so don’t know where to start.

I’d be grateful if anybody know’s a great place to start to learn about this? I’ve ideally got to get it done within a couple of days.

Thanks

Hey @coding_noobie,

Grab a fetch polyfill so you can easily make requests, from there it’s just sending requests for the data you need and handling the JSON responses.

fetch('/users.json')
  .then(function(response) {
    return response.json()
  }).then(function(json) {
    console.log('parsed json', json)
  }).catch(function(ex) {
    console.log('parsing failed', ex)
  })

I need to be able to send the file to somebody else for them to have a look at it, will this still work?

Sorry, I have no idea what you mean.

I’ve been given an api and need to get the data from it and then display it but I’ve got absolutely no idea of how to do it. The example you gave said about installing stuff on my computer and also used JSON (the api I’ve got is rest). If I install that stuff and then send the html file to somebody will they still be able to see it?

I’ve been given an api and need to get the data from it and then display it but I’ve got absolutely no idea of how to do it.

fetch('/users.json')
  .then(function(response) {
    return response.json()
  }).then(function(json) {
    // Show this data somewhere in the page
    console.log('parsed json', json)
  }).catch(function(ex) {
    console.log('parsing failed', ex)
  })

Most REST API’s still serve data in the JSON format. The code above fetches data from /users.json parses the JSON as a JavaScript object and lets you do what you want with that data.
You’ll need look at the API documentation and have a go a fetching data from it, it will become clearer how to work with it when you start working with the data.

Yes, you will be able to send the HTML file and other assets you need (JavaScript files) to someone else.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.