Class 8 - APIs
Lab 8 - APIs
Setup
In this lab assignment, you will show live weather and movie data in response to City Explorer searches. This data comes from third-party APIs, that allow you to make queries with an access token (or key). To keep your key secure, you can’t expose it in your front-end code, but you can use it from within your own custom back-end API server code you started in the last lab. Your web client will make a request to your custom API server, which will in turn use the key to make a request to the data API. When your server gets the data back, you can wrangle the data as you like, and send it on back to the web client.
Resources
Process
When available, your instructor will pair you with a partner for this lab. Review each other’s code from the previous lab and plan out an approach to this lab’s work on a whiteboard.
- Do a formal code review of each person’s code (10 minutes each).
- Open your partner’s GitHub pull request on your laptop.
- Identify an area in the code that:
- you don’t understand
- or seems overly complex
- or you see a way to improve
- or you want more information on
- or you really like or think is interesting
- Add kind comments or questions inline using the GitHub review feature.
- Draw the web request-response cycle for the current lab tasks (about 10 minutes).
- Document the data flow: identify inputs and outputs for each part of the cycle.
- Outline the functions that support this data flow.
- Be sure to include these drawings in your README.md.
- You will then work independently for the rest of the day, implementing your plan, coding in your own repository, submitting your own pull request.
Workflow
- We will be using the Trello project management tool for the duration of this project.
- To maximize your experience with Trello, you should create a free Trello account by clicking on the Sign Up button.
- After creating an account, go to the City Explorer Trello Board, open the “… Show Menu” link, click the “… More” link, and then click “Copy Board”. Before you create it, be sure to “Change” from Private to “Public” (and click “Yes, Make Board Public”) so your instructional team can see your work. Now, click “Create” to add a copy to your personal account.
- This Trello board contains all of the features required to complete this lab assignment.
- Review the user stories and analyze the feature requests and requirements in the lab.
Within each story, note the acceptance criteria (“Given … When … Then…”) and the checklist of feature tasks. Be careful to execute tasks in order as they are often dependencies of one another.
- Throughout the lab time, check off tasks as you complete them, and move the story cards through the workflow.
Documentation
Your README.md must include:
Project Name
Author: Your Name Goes Here
Version: 1.0.0 (increment the patch/fix version number if you make more commits past your first submission)
Overview
Getting Started
Architecture
Change Log
Credit and Collaborations
Time Estimates
For each of the lab features, make an estimate of the time it will take you to complete the feature, and record your start and finish times for that feature:
Name of feature: ****____****
Estimate of time needed to complete: _
Start time: _
Finish time: _
Actual time needed to complete: _
Add this information to your README.
Submission Instructions
- Complete your Feature Tasks for the lab, according to the Trello cards.
-
Your lab will require 2 repositories: 1 for the Server (back-end) and 1 for the client (front-end)
- Run your Lighthouse Accessibility report looking for a score of 65 or higher. Make adjustments as needed.
- Create a PR back to the main branch of your repository, showing ALL your work, and merge it cleanly.
- On Canvas, submit a link to your PR. Add a comment in your Canvas assignment which includes the following:
- A link to the deployed version of your latest code.
- A link to your public Trello board.
- A question within the context of this lab assignment.
- An observation about the lab assignment, or related ‘Ah-hah!’ moment.
- How long you spent working on this assignment.
Code Challenge - Array and String Methods Fun with split, join, slice, and splice!
Overview
Read this overview.
Video
Watch the video for this class from the demo playlist.
Demonstration
Look through these sample problems.
Challenges
Navigate to the javascript folder within your data-structures-and-algorithms repository.
-
Create a new branch for this challenge called array-methods
git checkout -b array-methods
-
Retrieve the code challenge from the system
npm run get-challenge 08
-
In your terminal, from the javascript folder, run npm test 08 to execute the tests in this file for this challenge.
-
At this point you will see the failed tests scroll through your terminal window with a brief report of the number of failed tests at the bottom.
-
If you do not see this, verify your installation of Jest by typing npx jest –version in your terminal. Filename typos can make things break!
-
Write code to make the tests pass, one at a time. Let the error messages guide you.
-
Once the test is passing, refactor as needed, then move on to the next challenge.
-
Note, you can also run npm test (without a challenge number) to run all of the tests for every code challenge file assignment during the course all at once. This can get “noisy”, but it’s an opportunity to get a view of your overall progress
Submission
When you have completed the entire set of code challenges and all tests pass, create a pull request from your current branch to the main branch and merge it into main.
You will be able to see a test coverage report in GitHub on the Actions tab of your data-structures-and-algorithms repository. It should match what you saw on your terminal in the above steps. Your graders will be looking at this as well.
Submit a link to your pull request.
Written Class Notes
errors come from the server side
200 success
500 broken
404 not found
403 forbidden api wrong
Use middle man to make it easier on client side, best practice to off load to backend service, no intelligence on client side
Read 8 - Readings Overview
Resources Link/Pages
Bookmark and Review
API Design Best Practices
- API Design Best Practices
Answer
Statement on why this topic matter as it relates to what I’m studying in this module:
APIs serve as the backbone for communication between different software components. REST provides a standardized architectural approach to designing these APIs.
API Design Best Practices
- What does REST stand for?
- Representational State Transfer.
- REST APIs are designed around a resource.
- What is an identifier of a resource? Give an example.
- URI (Uniform Resource Identifier). Example:
https://adventure-works.com/orders/1
- What are the most common HTTP verbs?
- GET, POST, PUT, PATCH, DELETE.
-
What should the URIs be based on?
- The nouns (the resource) and not verbs (the operations on the resource).
- Give an example of a good URI.
- Good:
https://adventure-works.com/orders
- Avoid:
https://adventure-works.com/create-order
- What does it mean to have a ‘chatty’ web API? Is this a good or a bad thing?
- When one that exposes a large number of small resources, leading to many requests. This is generally a bad thing as it increases the load on the server and may result in poor performance.
- What status code does a successful
GET request return?
- HTTP status code 200 (OK).
- What status code does an unsuccessful
GET request return?
- HTTP status code 404 (Not Found) if the resource cannot be found.
- What status code does a successful
POST request return?
- HTTP status code 201 (Created).
- What status code does a successful
DELETE request return?
- HTTP status code 204 (No Content).
The common HTTP methods used by most RESTful web APIs are:
- GET retrieves a representation of the resource at the specified URI. The body of the response message contains the details of the requested resource.
- POST creates a new resource at the specified URI. The body of the request message provides the details of the new resource. Note that POST can also be used to trigger operations that don’t actually create resources.
- PUT either creates or replaces the resource at the specified URI. The body of the request message specifies the resource to be created or updated.
- PATCH performs a partial update of a resource. The request body specifies the set of changes to apply to the resource.
- DELETE removes the resource at the specified URI.
Things I want to know more about
- What does it mean when it said REST APIs use a stateless request model and it enables web services to be highly scalable, because there is no need to retain any affinity between clients and specific servers? What can limit this scalability?
Retrospective
Retrospectives are a critical part of Agile, and typically take the form of meetings held by a team at the end of a sprint cycle. To get us acclimated to that process, we will use the format of a retrospectives to guide today’s reflection.
This article gives a nice overview to the role of retrospectives.
- What went well, that I might forget if I don’t write down?
- Two things went well but I forgot to write them down and now I don’t remember. I will blame that only getting two hours of sleep.
- What did I learn today?
- Some API sites make things so hard to use….
- What should I do differently next time?
- I should take notes when a TA is talking to me so I remember what helped.
- What still puzzles me, or what do I need to learn more about?
- I think no brainer everything about this week still confuses me.
Thinking about each of your assignments for the day, reflect on:
Is the assignment complete? If not, where exactly did you leave off, and what work remains?
It is not complete, I still have to do the hard part of fixing the movie data feth and also rendering that.
Career 8 - Professional Pitch and Introduction
Watch the videos:
- Job interview professional introduction: video
- How to give a personal pitch with little field experience: video
Now review the video of your professional pitch that you created earlier. It’s not easy to hear your own voice, or watch your own face, so be brave! This is one of the simplest ways to improve. Watch and listen carefully. Imagine you are hearing it for the first time.
Assignment
Re-record your pitch video, keeping the positives, and changing the things you’d like to improve.
Send your Career Coach, or a trusted mentor, the link to your pitch video to respond to you with their feedback. This exercise will better prepare you for the 401 Personal Pitch workshop where you will present your pitch to your classmates for their collective feedback.
Remember that feedback is a gift. Being receptive to ways you can improve is imperative when you are developing your story and your personal brand. Knowing what is working and what needs improvement early helps you practice with intention and excellence and be prepared for the interview process.
Submit the reworked version of your video to complete the assignment.
- Hello, I’m Xin Deng, transitioning from a career in veterinary clinic team management to the forward-thinking world of software development. In my role as a lead receptionist, I cultivated strong multitasking and problem-solving skills, but I felt a need for a more fulfilling and stable career. The allure of merging creativity with technology led me to software development, where I aspire to design user-friendly applications and contribute to groundbreaking innovations. My advantage lies in my extensive experience in client-facing roles, and understanding the importance of seamless user interactions. Thriving in collaborative environments, I am eager to leverage my problem-solving and communication skills to make a valuable impact on any software development team.