Skip to content

Updating swapi API endpoints for readers #19

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 15 additions & 15 deletions open-in-web-browser.html
Original file line number Diff line number Diff line change
Expand Up @@ -3422,7 +3422,7 @@ <h3>7.1 : Asynchronous Programming Basics</h3>
<strong>Notes:</strong>
</p>
<ol>
<li>An in-depth understanding of asynchronous programming in JavaScript requires an understanding of the call stack and the event-loop. Here is a simple and concise review of these parts, <a href="https://vimeo.com/96425312">"Help, I'm stuck in an event-loop."</a>. If you've struggled in the past with understanding promises it is likly because you lack the foundational information found in the aforementioned video.</li>
<li>An in-depth understanding of asynchronous programming in JavaScript requires an understanding of the call stack and the event-loop. Here is a simple and concise review of these parts, <a href="https://vimeo.com/96425312">"Help, I'm stuck in an event-loop."</a>. If you've struggled in the past with understanding promises it is likely because you lack the foundational information found in the aforementioned video.</li>
</ol>
</div>

Expand Down Expand Up @@ -3775,22 +3775,22 @@ <h3>7.6 : Chaining Promises with <code>then()</code></h3>

// chain a set of promise to occur one after the other
// check the starwars api to see if all endpoints are working.
fetch('https://swapi.co/api/people')
fetch('https://swapi.dev/api/people/')
.then((response)=>{
starWarsAPICheck.push(response.ok);
return fetch('https://swapi.co/api/planets');
return fetch('https://swapi.dev/api/planets/');
}).then((response)=>{
starWarsAPICheck.push(response.ok);
return fetch('https://swapi.co/api/films');
return fetch('https://swapi.dev/api/films/');
}).then((response)=>{
starWarsAPICheck.push(response.ok);
return fetch('https://swapi.co/api/species');
return fetch('https://swapi.dev/api/species/');
}).then((response)=>{
starWarsAPICheck.push(response.ok);
return fetch('https://swapi.co/api/vehicles');
return fetch('https://swapi.dev/api/vehicles/');
}).then((response)=>{
starWarsAPICheck.push(response.ok);
return fetch('https://swapi.co/api/starships');
return fetch('https://swapi.dev/api/starships/');
}).then(()=>{
console.log(starWarsAPICheck); // logs [true, true, true, true, true, true]
});
Expand Down Expand Up @@ -3883,7 +3883,7 @@ <h3>7.8 : Running a Final Function, Regardless of Promise Fulfillment State with
<pre class="line-numbers"><code class="language-js">
let stateOfLoading = 'Not Loading'; // this is the default state

fetch('https://swapi.co/api/peoples/') // breaks because the URL is people not peoples
fetch('https://swapi.dev/api/peoples/') // breaks because the URL is people not peoples
.then((response) => {
if(!response.ok){ // run if fetch fails
throw Error('api call broke'); // catch() is called
Expand Down Expand Up @@ -4129,25 +4129,25 @@ <h3>8.5 : The <code>await</code> operator is sequential</h3>
(async () => { // create async function that is immediately invoked

// sequential fetch's
const responsePlants = await fetch('https://swapi.co/api/planets');
const responsePlants = await fetch('https://swapi.dev/api/planets/');
// API call above has to finish before the API below can start
const responseFilms = await fetch('https://swapi.co/api/films');
const responseFilms = await fetch('https://swapi.dev/api/films/');

console.log(responsePlants.ok, responseFilms.ok) // logs true true

// parallel fetch's, faster than sequential fetch's using Promise.all()
const [parallelResponsePlanets, parallelResponseFilms] = await Promise.all([
fetch('https://swapi.co/api/planets'),
fetch('https://swapi.co/api/films')
fetch('https://swapi.dev/api/planets/'),
fetch('https://swapi.dev/api/films/')
]);

console.log(parallelResponsePlanets.ok, parallelResponseFilms.ok) // logs true true

// parallel fetch's, return first one to finish, using Promise.race()
const fastestResponseFromStarWarsApi = await Promise.race([
fetch('https://swapi.co/api/species'),
fetch('https://swapi.co/api/vehicles'),
fetch('https://swapi.co/api/starships')
fetch('https://swapi.dev/api/species/'),
fetch('https://swapi.dev/api/vehicles/'),
fetch('https://swapi.dev/api/starships/')
]);

console.log(fastestResponseFromStarWarsApi.ok); // logs true
Expand Down