This project is focused on creating a script to fetch and display characters from the Star Wars movies using the Star Wars API. The script will accept a movie ID as a command-line argument and display the character names in the same order as they appear in the movie.
The objective of this project is to interact with an external API to retrieve and display information about Star Wars characters based on a given movie ID. This involves understanding HTTP requests, working with APIs, asynchronous programming, and handling command-line arguments in Node.js.
- Editors: vi, vim, emacs
- Environment: Ubuntu 20.04 LTS
- Node.js Version: 10.14.x
- Code Style: Semi-standard compliant (Standard rules with semicolons)
- File Requirements:
- All files should end with a new line.
- The first line of all files should be
#!/usr/bin/node
. - All files must be executable.
- No use of
var
.
- Making HTTP requests to external services using the
request
module or alternatives likefetch
in Node.js. - Understanding the basics of making HTTP requests, handling responses, and parsing JSON data.
- Understanding RESTful APIs and how to interact with them.
- Parsing JSON data returned by APIs to extract relevant information.
- Managing asynchronous operations using callbacks, promises, and async/await syntax.
- Handling API responses asynchronously to ensure efficient data retrieval and processing.
- Using the
process.argv
array to access command-line arguments passed to a Node.js script. - Parsing and using these arguments effectively within the script.
- Iterating over arrays and manipulating data structures to format and display character names.
- Utilizing JavaScript array methods to handle and display data correctly.
To set up the environment for this project, follow these steps:
-
Install Node 10:
$ curl -sL https://deb.nodesource.com/setup_10.x | sudo -E bash - $ sudo apt-get install -y nodejs
-
Install semi-standard:
$ sudo npm install semistandard --global
-
Install the request module:
$ sudo npm install request --global $ export NODE_PATH=/usr/lib/node_modules
To run the script, use the following command format:
$ ./0-starwars_characters.js <Movie ID>
Example:
$ ./0-starwars_characters.js 3
Write a script that prints all characters of a Star Wars movie:
- Input: The first positional argument is the Movie ID (e.g., 3 for "Return of the Jedi").
- Output: Display one character name per line in the same order as the "characters" list in the
/films/
endpoint. - Requirements:
- Use the Star Wars API.
- Use the
request
module.
Example output for ./0-starwars_characters.js 3
:
Luke Skywalker
C-3PO
R2-D2
Darth Vader
Leia Organa
Obi-Wan Kenobi
Chewbacca
Han Solo
Jabba Desilijic Tiure
Wedge Antilles
Yoda
Palpatine
Boba Fett
Lando Calrissian
Ackbar
Mon Mothma
Arvel Crynyd
Wicket Systri Warrick
Nien Nunb
Bib Fortuna
For more information on the key concepts, refer to the following resources:
- A Complete Guide to Making HTTP Requests in Node.js
- Working with APIs in JavaScript
- Asynchronous Programming in JavaScript
- How to Parse Command Line Arguments in Node.js
- JavaScript Array Methods
By understanding and applying these concepts, you will be able to efficiently retrieve, process, and display Star Wars characters from the specified movie using the Star Wars API.