A project built around Biuni's PokeDex Data Set as an introduction to API's, working on large code bases, TDD, and Node.js.
To complete the projet "all" you have to do is complete the empty functions found in /functions
directory. The challenges themselves are at a JS-2/JS-3 level of difficulty so they will be a nice review of arrays, objects and array methods. The biggest challenge will be learning how to debug & develop the functions in Node.js, run the tests, and use your functions from the server in the main index.js
file.
One of the main learning objective of this project is figuring out how to explore, understand, and run modular applications that you didn't write. So even if you manage to pass all of the tests in a couple days, go back and practice runing the server. Read through every file in this project, try adding routes, understand what each file does and how it relates to the application as a whole. The challenges themselves may be review but running the tests, using your functions from the server, and finding your way through this application are all Node.js level skills.
Enjoy!
- Debugging JavaScript in VSC
- Running tests from the terminal with mocha
- Building report logs
- Using
npm
: installing dependencies, running scripts - Understanding what "fullstack" means
- Working with modular code
- Using branches
- Navigating larger directory structures
- Understanding code you didn't write
- Setting up and running other people's projects
- Exploring and understanding large data sets
- Reading and understanding JSON data
- Processing more data than you can read at once
- Deciphering JSON schemas
- Explaining why you can't run an API with the browser
- Running API's with Node.js & VSC
- Testing them with the browser and Postman
- Understanding the need for CORS
- URL Request parameters
Before you start passing tests, you should install all dependencies and practice using the app. It'll be much easier to solve the challenges after you are comfortable running and exploring the code base.
all scripts should be run in terminal from the top level of this project
- clone the repo
npm install
npm install -g mocha
(if you don't have it yet)
npm run dev
- Studying in Postman:
- go to
localhost:xxxx/docs
for API documentation - explore!
- go to
- Studying in the Browser:
- go to
localhost:xxx/
for the simple frontend & docs - open your console to study the API's responses
- explore!
- go to
- To test a single function at a time while writing your solutions:
mocha functions/path-to-function/spec.js
- To test all functions at once:
npm run test
- To build an updated
report.json
in the./functions
directorynpm run report
Psst. don't forget to use branches! Develop each of these functions on their own branch, only merging them to master when all of the test pass.
The good news is almost all of the code is already written, and it already works! All you need to write is the bodies for the 8 functions in ./functions
. Each of the functions are used by the API to process the PokeDex data and return just the information a user needs.
Each function lives in it's own small directory with a descriptive name, with three files:
index.js
: Contains the empty function you need to write. Your function is exported from this file for testing, development, and deployment.spec.js
: Test cases and mocha suites for each function are described in this file. The test data is pulled from the sample data sets in./data
.sandbox.js
: An empty file for your experiments. It's not connected to any build or testing scripts, the API doesn't use it, it's just there for you to debug and play around with your function. Each sandbox has 4 dependencies:./index.js
: the function you are currently working onpokedex
: the full pokedex data setpokeData
: the complete array of pokemon objects used by the APIsamples
: the sample data sets used by the test casesassert
: a native Node.js module for asserting, you can think of it likeconsole.assert
on steroids
Below are the 8 functions you need to write:
- ARGS:
pokeArray
: An array of Pokemon objects.key
: A string
- RETURNS: Array of values
- BEHAVIOR: This function will create a new array containing every unique value associated with the given
key
. If two pokemon objects have the same value for thekey
, then the value will not be added twice.
- ARGS:
pokeArray
: An array of Pokemon objects.name
: A string
- RETURNS: Array of objects ->
{name: "string", num: "string"}
- BEHAVIOR: This function will return an array indicating all evolutions of the pokemon with
name
. Each object in the array will contain only the .name and .num of each evolution. If there is no pokemon withname
, the function will return an empty array.
- ARGS:
pokeArray
: An array of Pokemon objects.type
: A string
- RETURNS: an object with three properties ->
{typeName: "string", typeCount: "number", weaknessCount: "number"}
- BEHAVIOR: This function will check every pokemon to build up the return value. The
.typeCount
property in the return value is a count of how many pokemon have thistype
in the .type array. The.weaknessCount
property shows how many pokemon have thistype
in their .weaknesses array.
- ARGS:
pokeArray
: An array of Pokemon objects.id
: A number
- RETURNS: A pokemon object
- BEHAVIOR: This function returns the pokemon object with the given
id
. If no such pokemon exists, it returns an empty object.
- ARGS:
pokeArray
: An array of Pokemon objects.key
: A stringvalue
: A string
- RETURNS: Array of objects ->
{name: "string", num: "string"}
- BEHAVIOR: This function returns an array indicating which pokemon objects have a key/value pair matching the
key
andvalue
arguments. Because your req.params will always be strings (until you learn about req.body ;), the function will cast all saved values to String before comparing withvalue
.
- ARGS:
pokeArray
: An array of Pokemon objects.type
: A string
- RETURNS: Array of objects ->
{name: "string", num: "string"}
- BEHAVIOR: This function returns an array indicating which pokemon objects have the given
type
in their .type array. If there are no pokemon with thistype
, just return an empty array.
- ARGS:
pokeArray
: An array of Pokemon objects.value
: A string
- RETURNS: Array of objects ->
{name: "string", num: "string"}
- BEHAVIOR: This function returns an array indicating which pokemon objects have the given
value
stored in any of their keys. Because your req.params will always be strings (until you learn about req.body ;), the function will cast all saved values to String before comparing withvalue
.
- ARGS:
pokeArray
: An array of Pokemon objects.weakness
: A string
- RETURNS: Array of objects ->
{name: "string", num: "string"}
- BEHAVIOR: This function returns an array indicating which pokemon objects have the given
weakness
in their .weaknesses array. If there are no pokemon with thisweakness
, just return an empty array.
If you've finished all 7 functions and are comfortable testing your API locally (using Postman and the Browser), the next step is to deploy your project.
Follow the steps in this tutorial to push your Pokemon API to Heroku for your first live, fullstack web app!
hi!