Code Monkey home page Code Monkey logo

animated-tribble's Introduction

TypeScript API Demo

My Approach

I started by dividing up the problem into four major components/responsibilities:

  1. A server to receive and route API requests to a controller
  2. A controller that forms requests into a domain-specific query for the business logic layer
  3. A business logic layer that does the heavy lifting of the problem: interpreting the query and performing the filtering and sorting
  4. A CSV reader that turns the flat file into domain objects for the business logic layer to work with

The business logic layer is where the challenging problem lies; all the rest is wiring. So I decided to focus on that as the center of the design. It was critical that the interfaces on either side of it were sensible and easy to drop into a test harness. I spent the majority of my time deciding on how to lay out the interfaces and crafting the unit tests. When it could stand on its own, I set up the server in server.ts and resolved the dependencies, making a basic controller and shopping for a decent CSV reader.

Improve or additions

  • Tests for server
  • Clean up controller test
  • Come up with a better name for the business logic layer (OrganizationData)
  • Refactor the OrganizationData tests for clarity

Getting it up and running

Building

It's a Node.js project, so we'll need to start with the typical Node.js prep. First, either install the latest Node.js runtime or have nvm get it for you, using the .nvmrc file:

nvm install

Now that we have the correct Node.js version, install the project's dependencies:

npm install

Running Tests

Run the Jest tests as you would for any other Node.js project:

npm test

Executing

Since this is a TypeScript project, the start script will also do a build prior to starting the server with node:

npm start

Exercising the API

You can reach the API via localhost:3000. For example: http://localhost:3000/organizations?category=Greek&city=Washington.

animated-tribble's People

Contributors

doingweb avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.