Previous Lecture Lecture 17 Next Lecture

Lecture 17, Thu 05/05

Thu Lecture: Front End Development

Announcements

Reminder about H07: start learning JavaScript!

Front End Development

Today, we’ll go over some JavaScript and front end development concepts.

First, here’s a cheat sheet of useful stuff:

Where do you map pages to routes in React?

In our React app, pages are mapped to routes in the file frontend/src/App.js

Example:


Front end testing:

Running on Localhost:

On localhost, we run the backend in one terminal window, and the frontend in a separate terminal window.

The first time

The backend is started in the usual way:

For the frontend, start a separate terminal window, and then do this:

The normal case

Usually, it’s just:

Accessing swagger endpoint

On localhost, there is a link to access swagger, but on Heroku, there is usually not.

To access it you can add /swagger-ui/index.html to the end of the URL. Note that the /index.html is required in this case.

For example: https://cs156-s22-starter-team03.herokuapp.com/swagger-ui/index.html

Codecov

Be sure to visit the codecov page corresponding to your repo, i.e.

And go to the Settings page and change the default branch from master to main.

image

Then, you can get the badge (see Badge in left navigation), copy the Markdown version of the badge, and put it at the top of your README.md.

image

Sample Data from UCSB Developer API

The UCSB Developer API provides access to various kinds of data. Many of the endpoints can provide sensitive data, so they are protected and require higher levesl of approval and authorization, but some of them provide data that is not all that sensitive (i.e. it is generally available to the public) and so the levels of approval are reduced. These are marked as “auto-approved” endpoints.

I’ve created a credential for use ONLY of the students in CS156 S22 and have provided it on the slack for the course. This should only be used for course activities (I will invalidate it with the course is over; if you want to continue using the APIs after that, please apply for you own credential.)

Here is the list of APIs you can access with this credential:

image

For this demo, we may need some sample data. Here is some sample data for UCSB Dining Commons, from the UCSB Api.

We can access this at the command line using curl like this:

curl -X 'GET' \
  'https://api.ucsb.edu/dining/commons/v1/' \
  -H 'accept: application/json' \
  -H 'ucsb-api-key: put-the-consumer-key-here'

The endpoint gives us this data (if supplied with a valid API consumer key):

[
  {
    "name": "Carrillo",
    "code": "carrillo",
    "hasSackMeal": false,
    "hasTakeOutMeal": false,
    "hasDiningCam": true,
    "location": {
      "latitude": 34.409953,
      "longitude": -119.85277
    }
  },
  {
    "name": "De La Guerra",
    "code": "de-la-guerra",
    "hasSackMeal": false,
    "hasTakeOutMeal": false,
    "hasDiningCam": true,
    "location": {
      "latitude": 34.409811,
      "longitude": -119.845026
    }
  },
  {
    "name": "Ortega",
    "code": "ortega",
    "hasSackMeal": true,
    "hasTakeOutMeal": true,
    "hasDiningCam": true,
    "location": {
      "latitude": 34.410987,
      "longitude": -119.84709
    }
  },
  {
    "name": "Portola",
    "code": "portola",
    "hasSackMeal": true,
    "hasTakeOutMeal": true,
    "hasDiningCam": true,
    "location": {
      "latitude": 34.417723,
      "longitude": -119.867427
    }
  }
]