Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
**/node_modules/*
**/vendor/*
**/*.min.js
**/coverage/*
**/build/*
41 changes: 41 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
{
"env": {
"browser": true,
"node": true,
"commonjs": true,
"jest": true,
"es6": true
},
"globals": {
"err": true,
"req": true,
"res": true,
"next": true
},
"extends": "eslint:recommended",
"parserOptions": {
"sourceType": "module"
},
"rules": {
"no-console": "off",
"indent": [
"error",
2
],
"quotes": [
"error",
"single",
{
"allowTemplateLiterals": true
}
],
"comma-dangle": [
"error",
"always-multiline"
],
"semi": [
"error",
"always"
]
}
}
5 changes: 5 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@

* text=auto

# Align with eslint linebreak-style: [ "error", "unix" ]
*.js text eol=lf
8 changes: 8 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@

language: node_js
node_js:
- "9"

script:
- npm run lint
- npm test
80 changes: 2 additions & 78 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,84 +1,8 @@
![cf](https://i.imgur.com/7v5ASc8.png) Lab 08: REST
======

## Submission Instructions
* Work in a fork of this repository
* Work in a branch on your fork
* Create a PR to your master from your working branch.
* Ensure that your repository/branch is connected to travis-ci.com
* Ensure that your repository/branch is connected to a dyno at heroku.com
* Heroku and Travis should pick you up and deploy
* Submit on canvas:
* a question and observation
* how long you spent
* link to your pull request
* link to your build at travis-ci URL
* Heroku Server URL
## Submission

## Configuration
Configure the root of your repository with the following files and directories. Thoughfully name and organize any aditional configuration or module files.
* **README.md** - contains documentation
* **.env** - contains env variables (should be git ignored)
* **.gitignore** - contains a [robust](http://gitignore.io) `.gitignore` file
* **.eslintrc** - contains the course linter configuratoin
* **.eslintignore** - contains the course linter ignore configuration
* **.travis.yml** - contains the course linter ignore configuration
* **package.json** - contains npm package config
* create a `lint` script for running eslint (eslint **/*.js)
* create a `test` script for running tests
* create a `start` script for running your server
* **index.js** - the entry point for your application
* **src/** - contains your core application files and folders
* **src/app.js** - (or main.js) contains your core application bootstrap
* **src/lib/** - contains module definitions
* **\_\_test\_\_/** - contains unit tests
[![Build Status](https://travis-ci.com/tamarushin/08-rest.svg?branch=master)](https://travis-ci.com/tamarushin/08-rest)

## Learning Objectives
* students will learn to use promise constructs to manage asynchronous code
* students will learn to create a vanilla RESTful API

#### Feature Tasks
* create the following directories to organize your code:
* `src`
* `src/lib`
* `src/api`
* `__test__`
* create an HTTP server using the native NodeJS `http` module
* create a custom parser module that:
* uses promises to parse the JSON body of `POST` and `PUT` requests
* uses the NodeJS `url` and `querystring` modules to parse the request url
* create a router constructor that allows you to register custom routes for `GET`, `POST`, `PUT`, and `DELETE` requests
* create a router constructor that handles requests to `GET`, `POST`, `PUT`, and `DELETE` using the custom routes defined

## Server Endpoints
### `/api/v1/simple-resource-name`
**These will be "proof of life" endpoints, to prove server health**

NOTE: simple-resource-name is left up to you. E.g. dog, cat, whatever...

* `POST` request
* pass data as stringifed JSON in the body of a **POST** request
* return a 200 response with the POST'd JSON as the content
* (Prove that you got the JSON from the POST)
* `PUT` request
* pass `?id=<uuid>` as a query string parameter to identify a specific resource
* pass data as stringifed JSON in the body of a **PUT** request
* return a 200 response with the JSON as the content
* (Prove that you got the JSON from the PUT)
* `GET` request
* pass `?id=<uuid>` as a query string parameter to identify a specific resource
* return a 200 response, and a message that states "ID: <id>" was requested
* (Prove that you got the id from the query string)
* `DELETE` request
* pass `?id=<uuid>` as a query string parameter to identify a specific resource
* return a 200 response, and a message that states "ID: <id>" was deleted
* (Prove that you got the id from the query string)

## Tests
* write a test to ensure that your api returns a status code of 404 for routes that have not been registered
* write tests to ensure the `/api/simple-resource-name` endpoint responds as described for each condition below:
* `GET`: test 404, it should respond with 'not found' for valid requests made with an id that was not found
* `GET`: test 400, it should respond with 'bad request' if no id was provided in the request
* `GET`: test 200, it should contain a response body for a request made with a valid id
* `POST`: test 400, it should respond with 'bad request' if no request body was provided or the body was invalid
* `POST`: test 200, it should respond with the body content for a post request with a valid body
15 changes: 15 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@

'use strict';

// 3rd Party Library
//utilize the env file or what PORT to go to.
require('dotenv').config();

// Local Library
const server = require('./src/app.js');

// Fire up the server, on the port that we pulled out of our .env file
// Note that there is NO default port given!
server.start(process.env.PORT, () => console.log(`Server up on ${process.env.PORT}`))
//server. dot means that it is an object
//.start is a method
Loading