/pokedex-api

Primary LanguageHTMLMIT LicenseMIT

PokeDex API

A series of exercises built around Biuni's PokeDex Data Set.

"All" you have to do is complete the empty functions found in /logic directory. The challenges require you to filter, map, search & reduce the pokemon dataset (early returns are your friend!). Because these exercises are all about the data, take some time to investigate it before diving right in. What do the schemas say? What do you find in the sample data?

Enjoy!

Index


Learning Objectives

Programming Skills

  • Debugging JavaScript in VSC
  • Running tests from the terminal with mocha
  • Working with modular code

Other People's Code

  • Navigating larger directory structures
  • Understanding code you didn't write
  • Setting up and running other people's projects

Working with Data

  • Exploring and understanding large data sets
  • Reading and understanding JSON data
  • Processing more data than you can read at once
  • Deciphering JSON schemas

APIs

  • Testing APIs in Postman
  • URL Request parameters
  • Using APIs to explore a large data set

Getting Started

Before you start passing tests, you should install all dependencies and practice running. It'll be much easier to solve the challenges after you are comfortable running and exploring the code base.

Install & Dependencies

  1. clone the repo
  2. npm install
  3. npm install -g mocha

Running the Tests

  • To test a single function at a time while writing your solutions:
    • mocha logic/path-to-function/spec.js
  • To test all functions at once:
    • npm run test

Test results will be logged to the terminal and rendered to the folder called /mochawesome-report. To explore the test results in your browser, open /mochawesome-report/mochawesome.html in your browser.

Running the API

  • npm run dev

TOP


Logic

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 ./logic. 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, and two files with standard names:

  1. index.js: Contains the empty function you need to write. Your function is exported from this file to be used in the routes.
  2. 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.

Below are the 8 functions you need to write:

logic/values-for-key

  • ARGS:
    1. pokeArray: An array of Pokemon objects.
    2. 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 the key, then the value will not be added twice.

logic/evolutions-of

  • ARGS:
    1. pokeArray: An array of Pokemon objects.
    2. 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 with name, the function will return an empty array.

logic/type-stats

  • ARGS:
    1. pokeArray: An array of Pokemon objects.
    2. 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 this type in the .type array. The .weaknessCount property shows how many pokemon have this type in their .weaknesses array.

logic/find-by/id

  • ARGS:
    1. pokeArray: An array of Pokemon objects.
    2. 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.

logic/find-by/key-value

  • ARGS:
    1. pokeArray: An array of Pokemon objects.
    2. key: A string
    3. value: 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 and value 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 with value.

logic/find-by/type

  • ARGS:
    1. pokeArray: An array of Pokemon objects.
    2. 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 this type, just return an empty array.

logic/find-by/value

  • ARGS:
    1. pokeArray: An array of Pokemon objects.
    2. 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 with value.

logic/find-by/weakness

  • ARGS:
    1. pokeArray: An array of Pokemon objects.
    2. 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 this weakness, just return an empty array.

TOP


API

Write the handlers!

TOP


Helpful Links

pokedex-api step-through

Before diving right into API's, Express and Servers it's worth spending a day or so just getting used to programming in Node.js. While the core of JavaScript is still the same there are some new features available in Node.js that weren't available in the browser, and it will take a little time to get used to working with the JS debugger built into VSC.

To get a hang of programming in Node.js take some time to solve the first few of these ...

  • JavaScript Exercises None of the first exercises are very difficult (you've even solved a few of them already!) so they should be a good opportunity to review JS and get used to the Node JS environment.

You aren't required to complete all of these exercises, but if you don't start them we will raise our eye-brows. So please include a link to your fork of the javascript-exercises in your weekly issue so we can easily find it.

Debugging JS In VSC

Node.js Tutorials

These tutorials will introduce you to a bunch of new features in Node that you haven't seen in the Browser. While you're following these tutorials, it's important to remember that at it's core Node.js is still JavaScript. Everything you've learned so far (except for the DOM & fetch :) is still true! The Event Loop, Classes, Closure, Arrays, Objects, Variables, this., it's all still the same.

The tutorials below will introduce to what's new and what's special about Node. But don't forget to take some time and solve a few of the JavaScript Exercises above to get used to working with plain, vanilla JS in the terminal.

API's and Express

Node.js is a JavaScript runtime environment capable of writing Web Servers and API's all by itself. But it's a bit annoying. Express is a great and easy to use framework to help you write API's and Web Servers by handling all of the boring stuff for you so you can focus on what your app does.

JSON Server - An NPM module that starts a RESTful API without you having to write a single line of code. This can be helpful practice for getting the hang of API's and Postman without getting caught up with bugs and errors.

TOP