Skip to content

MartinRosenberg/weather-api

Repository files navigation

Weather API

Setup

  1. Download and install:
    git clone https://github.com/MartinRosenberg/weather-api.git
    cd weather-api
    yarn
  2. Add your API key:
    echo "OWM_API_KEY = [your API key]" > .env
  3. Run:
    yarn start:dev

Completing the assignment

At no point did I get a solid, uninterrupted block of time to work on this, so it was nearly impossible to track time spent on this.

Tooling choice

I chose to use NestJS over the other options as it is your current favorite for use on the upcoming work, so it made sense to use this as an opportunity to learn relevant skills.

Response structure

I made the response an object with the ZIP codes as keys, as opposed to an array, to keep the data organized because the order of the ZIP codes in the query is likely quite arbitrary. I find this makes the data easier to conceptualize and read. The tradeoff is that the end user needs to convert it to an array themselves to map over, if they're only using vanilla JS data structures and utilities.

For the interior structure, however, I went the other way: instead of making the individual weather data an object keyed with dateTimes, I made the dateTimes into values in an array. This is because, while the JSON dates are strings, they're likely to be converted into other formats using native Date, moment.js, or date-fns, and those objects can't be object keys; that would've been a much bigger tradeoff.

Testing

Testing has all been removed from this application, as the spec calls for maximally simple code and documentation, and does not call for testing, which would then only serve to complicate the code. In a real-world application, this would not be the case.

To do

Given more time:

  • Add testing
  • Add Swagger (not swagger, but maybe also that)

Resources used

These resources were used in whole or in part - usually in small part, as you might guess from the number of them.

I didn't have any real prior experience with NestJS, Axios, RxJS, which cost me a bit of extra learning time.

NestJS basics

Axios basics

Calling the OpenWeatherMap API

Using the API data

Error handling

NestJS examples

Some other NestJS APIs I found in my searching also happened to use the OWM API, though you'll see my code is still rather different from theirs.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published