akbelcolak / pokedex-api

Akbel: pokedex-api

Home Page:https://akbelcolak.github.io/pokedex-api/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

PokeDex API

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!

Index


Learning Objectives

Programming Skills

  • 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

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

API's

  • 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

Getting Started

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

Install & Dependencies

  1. clone the repo
  2. npm install
  3. npm install -g mocha (if you don't have it yet)

Running the API

  • npm run dev
  • Studying in Postman:
    1. go to localhost:xxxx/docs for API documentation
    2. explore!
  • Studying in the Browser:
    1. go to localhost:xxx/ for the simple frontend & docs
    2. open your console to study the API's responses
    3. explore!

Running the Tests

  • 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 directory
    • npm run report

TOP


Your Task

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:

  1. index.js: Contains the empty function you need to write. Your function is exported from this file for testing, development, and deployment.
  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.
  3. 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 on
    • pokedex: the full pokedex data set
    • pokeData: the complete array of pokemon objects used by the API
    • samples: the sample data sets used by the test cases
    • assert: a native Node.js module for asserting, you can think of it like console.assert on steroids

Below are the 8 functions you need to write:

values-for-key.js

  • 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.

evolutions-of.js

  • 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.

type-stats.js

  • 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.

find-by/id.js

  • 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.

find-by/key-value.js

  • 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.

find-by/type.js

  • 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.

find-by/value.js

  • 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.

find-by/weakness.js

  • 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


Extra Challenge

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!

TOP


Helpful Links

hi!

TOP



Hack Your Future: Belgium

About

Akbel: pokedex-api

https://akbelcolak.github.io/pokedex-api/

License:Other


Languages

Language:JavaScript 81.4%Language:HTML 18.6%