Giter Club home page Giter Club logo

hyf-api's Introduction

XMLHttpRequest Example Application

Overview

This repo provides a starter web application with supporting backend application for demonstrating how to use the XMLHttpRequest browser object for accessing a Web API.

The Web API exposed here provides information about Nobel Prize Winners and Nobel Laureates, i.e. persons or organizations that have been awarded a Nobel Prize.

Although there is an online NobelPrize.org API, it was chosen for this repo to provide the Laureate and Prize information through a local backend, so that the application can be demonstrated and extended without the need for an Internet connection. However, the actual Nobel Prize data used here was downloaded in JSON data format through the official API.

Installation

To install this application, follow these steps:

  1. (Optionally) fork this repo to your own GitHub account.

  2. Clone the (forked) repo to your local machine.

  3. Open the repo folder in VSCode.

  4. Open the Integrated Terminal and type:

    npm install
    

Operation

  1. Start the backend with the following command:

    npm start
    
  2. Open your browser and type the following in the address bar:

    http://localhost:3000
    

This will open the web application. The application as cloned is unfinished. It just displays this screen:

InitialScreen

Folder Structure

public

This folder contains the frontend application, initially consisting of these files:

  • index.html
  • app.js
  • style.css

This is where you should make modifications, such as adding an XMLHttpRequest and handling the returned data.

server

This folder contains the supporting backend application. For this exercise you should not need to modify anything in here. The backend makes use of the json-server node package.

assets

This folder just contains the picture used in this README file.

API

Nobel Prizes

The backend application exposes the following Web API end point for Nobel Prizes:

http://localhost:3000/prizes

This particular end point returns information about all Nobel Prizes.

You can query the endpoint for more specific data by adding a query string to the url. For instance:

http://localhost:3000/prizes?category=economics

The information returned has the following JSON format (only the first two matching prize winners are shown).

[
  {
    "year": "2017",
    "category": "economics",
    "laureates": [
      {
        "id": "949",
        "firstname": "Richard H.",
        "surname": "Thaler",
        "motivation": "\"for his contributions to behavioural economics\"",
        "share": "1"
      }
    ]
  },
  {
    "year": "2016",
    "category": "economics",
    "laureates": [
      {
        "id": "935",
        "firstname": "Oliver",
        "surname": "Hart",
        "motivation": "\"for their contributions to contract theory\"",
        "share": "2"
      },
      {
        "id": "936",
        "firstname": "Bengt",
        "surname": "Holmström",
        "motivation": "\"for their contributions to contract theory\"",
        "share": "2"
      }
    ]
  }
]

Nobel Laureates

The backend application exposes the following Web API end point for Nobel Laureates:

http://localhost:3000/laureates

As specified, this particular end point returns information about all Nobel Laureates.

You can query the endpoint for more specific data by adding a query string to the url. For instance:

http://localhost:3000/laureates?surname=Dylan

The information returned has the following JSON format:

[
  {
    "id": "937",
    "firstname": "Bob",
    "surname": "Dylan",
    "born": "1941-05-24",
    "died": "0000-00-00",
    "bornCountry": "USA",
    "bornCountryCode": "US",
    "bornCity": "Duluth, MN",
    "gender": "male",
    "prizes": [
      {
        "year": "2016",
        "category": "literature",
        "share": "1",
        "motivation": "\"for having created new poetic expressions within the great American song tradition\"",
        "affiliations": [
          []
        ]
      }
    ]
  }
]

More information

For information on how to construct other query strings, e.g. to filter information using specific criteria check the documentation of json-server here.

hyf-api's People

Contributors

remarcmij avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.