From d0e9d14076e9d028a30eaf19d5a18e0658de046a Mon Sep 17 00:00:00 2001 From: lizzkats Date: Mon, 20 Mar 2017 11:52:26 -0700 Subject: [PATCH 01/20] adds readme and package.json --- README.md | 102 ++++++++++++++++++++++++++++++++++++++++++++++++++- package.json | 19 ++++++++++ 2 files changed, 120 insertions(+), 1 deletion(-) create mode 100644 package.json diff --git a/README.md b/README.md index fc28569..b48d979 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,102 @@ # Postalicious -A clone of the Postman chrome extension +A clone of the Postman chrome extension. + +## Description +See http://jsdev.learnersguild.org/goals/194-Postalicious-Demystifying_HTTP.html for description. + + +- [x] The artifact produced is a repo with at least two sub-folders: postalicious/ and sandbox-server/. +- [x] The artifact produced is properly licensed, preferably with the MIT license. + +## Sandbox Server + +- [ ] Can run the command npm run sandbox-server (or npm run sb, if you want to save some typing) to start the sandbox web server at port 3000. +- [ ] The sandbox server source code is written using the Express library. +- [ ] Sending a GET request to the path / responds with + - [ ] a 200 (OK) status code a plain-text response + - [ ] body with the content Welcome to Sandbox! + - [ ] the Content-Type header set to text/plain +- [ ] Sending a GET request to the path /search?q=doodads responds with + - [ ] a 200 (OK) status code + - [ ] a plain-text response body with the content You searched for: "doodads" (it doesn’t need to actually do any searching, just return the plain text) + - [ ] the Content-Type header set to text/plain +- [ ] Sending a GET request to the path /search responds with… + - [ ] a 400 (Bad Request) status code + - [ ] a plain-text response body with the content You didn't provide a search query term :( + - [ ] the Content-Type header set to text/plain +- [ ] Sending a POST request to the path /things with a plain text body flying car responds with… + - [ ] a 201 (Created) status code + - [ ] a plain-text response body with the content New thing created: "flying car"! (it doesn’t need to actually create anything, just return the plain text) + - [ ] the Content-Type header set to text/plain +- [ ] Sending a GET request to the path /somefile with an Accept header of text/plain responds with… + - [ ] a 200 (OK) status code + - [ ] a plain-text response body with the content This is a plain text file + - [ ] the Content-Type header set to text/plain +- [ ] Sending a GET request to the path /somefile with an Accept header of text/html responds with… + - [ ] a 200 (OK) status code + - [ ] an HTML response body with the content This is an HTML file + - [ ] the Content-Type header set to text/html +- [ ] Sending a GET request to the path /myjsondata with an Accept header of application/json responds with… + - [ ] a 200 (OK) status code + - [ ] an HTML response body with the content { "title": "some JSON data" } + - [ ] the Content-Type header set to application/json +- [ ] Sending a GET request to the path /old-page responds with… + - [ ] a 301 (Moved Permanently) status code + - [ ] the Location header set to http://localhost:3000/newpage +- [ ] Sending a POST request to the path /admin-only responds with a 403 (Forbidden) status code +- [ ] Sending a GET request to the path /not-a-page responds with a 404 (Not Found) status code +- [ ] Sending a GET request to the path /server-error responds with a 500 (Internal Server Error) staus code + + +##Postalicious + +- [ ] Can run the command npm run postalicious (or npm run pl, if you want to save some typing) to start the Postalicious app at port 3001. +- [ ] Users can visit the main page of the Postalicious site at http://localhost:3001. +- [ ] Main page has three main sections: + - [ ] Request builder HTML form + - [ ] Raw HTTP request + - [ ] Raw HTTP response +- [ ] When a user fills out the HTML form and clicks a “Send” button… + - [ ] The raw HTTP request is generated and shown + - [ ] The HTTP request is sent, and the raw response message is shown + - [ ] Users can fill out an HTML form to specify HTTP request details. +- [ ] Submitting the form will send the request according to the specified details. +- [ ] Using the HTML form, users can specify… + - [ ] host and path + - [ ] HTTP verb/method + - [ ] query parameter keys + values + - [ ] header keys + values + - [ ] request body + +##Stretch + +Use the stretch goals to go deeper into the nuts and bolts of HTTP. + +- [ ] Sandbox server is written using only the core Node.js modules (instead of Express, use the built-in HTTP module). +- [ ] Users of Postalicious can “save” their requests in a history panel +- [ ] Clicking on a saved request will re-load it into the form +- [ ] Using Postalicious, create some HTTP requests to various real-world APIs: +- [ ] Get all issues for a repo through the GitHub API +- [ ] Get all tweets with the hashtag #javascript with the Twitter API +- [ ] Any other API request(s) of your choice +- [ ] External HTTP requests are saved in files under a example-requests/ directory (make sure to obscure any secure information before saving these files, like your password or authentication token) + +##Quality Rubric + +* Well formatted code + +* Code uses a linter, which can be invoked with a command (e.g. npm run lint). [50 points] +* Running the linter on all source code files generates no linting errors. [50 points] +* Clear and useful README + +* Repository includes a README file with installation and setup instructions. [25 points] +* Repository includes a README file with usage instructions and at least one example use case. [25 points] +* Proper dependency management + +* There is a command to install dependencies (e.g. npm install) and it is specified in the installation and setup instructions of the README. [50 points] +* Good project management + +* Commit messages are concise and descriptive. [25 points] +* All features are added via pull requests. [25 points] +* Every pull request has a description summarizing the changes made. [25 points] +* Every pull request has been reviewed by at least one other person. [25 points] diff --git a/package.json b/package.json new file mode 100644 index 0000000..c538852 --- /dev/null +++ b/package.json @@ -0,0 +1,19 @@ +{ + "name": "postalicious", + "version": "1.0.0", + "description": "A clone of the Postman chrome extension.", + "main": "index.js", + "scripts": { + "test": "echo \"Error: no test specified\" && exit 1" + }, + "repository": { + "type": "git", + "url": "git+https://github.com/lizzkats/Postalicious.git" + }, + "author": "", + "license": "ISC", + "bugs": { + "url": "https://github.com/lizzkats/Postalicious/issues" + }, + "homepage": "https://github.com/lizzkats/Postalicious#readme" +} From 58ce6e9709f61fa5aba43752b4e7f8cb91726af2 Mon Sep 17 00:00:00 2001 From: lizzkats Date: Mon, 20 Mar 2017 17:18:14 -0700 Subject: [PATCH 02/20] adds testing and some modulating operations --- .gitignore | 1 + package.json | 14 +- sandbox-server/index.js | 19 +++ sandbox-server/routes/trails.js | 1 + sandbox-server/test/sandbox_tests.js | 185 +++++++++++++++++++++++++++ 5 files changed, 218 insertions(+), 2 deletions(-) create mode 100644 .gitignore create mode 100644 sandbox-server/index.js create mode 100644 sandbox-server/routes/trails.js create mode 100644 sandbox-server/test/sandbox_tests.js diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..3c3629e --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +node_modules diff --git a/package.json b/package.json index c538852..38c2155 100644 --- a/package.json +++ b/package.json @@ -4,7 +4,8 @@ "description": "A clone of the Postman chrome extension.", "main": "index.js", "scripts": { - "test": "echo \"Error: no test specified\" && exit 1" + "start": "nodemon sandbox-server/index", + "test": "mocha sandbox-server/test/sandbox_tests.js" }, "repository": { "type": "git", @@ -15,5 +16,14 @@ "bugs": { "url": "https://github.com/lizzkats/Postalicious/issues" }, - "homepage": "https://github.com/lizzkats/Postalicious#readme" + "homepage": "https://github.com/lizzkats/Postalicious#readme", + "dependencies": { + "express": "^4.15.2", + "morgan": "^1.7.1" + }, + "devDependencies": { + "chai-http": "^3.0.0", + "mocha": "^3.2.0", + "chai": "^3.5.0" + } } diff --git a/sandbox-server/index.js b/sandbox-server/index.js new file mode 100644 index 0000000..167e3e8 --- /dev/null +++ b/sandbox-server/index.js @@ -0,0 +1,19 @@ +const express = require('express') +const server = express() +const http = require('http').createServer(server) +const path = require('path') +const port = process.env.PORT || 3000 +const logger = require('morgan') + +server.use(logger("combined")) +server.use(express.static(path.join(__dirname, 'public'))) + +server.get('/', function(request, response){ + response.send('Hello World') +}) + +server.set(port) + +http.listen(port) + +module.exports = server diff --git a/sandbox-server/routes/trails.js b/sandbox-server/routes/trails.js new file mode 100644 index 0000000..75fc9ff --- /dev/null +++ b/sandbox-server/routes/trails.js @@ -0,0 +1 @@ +const express = require('express') diff --git a/sandbox-server/test/sandbox_tests.js b/sandbox-server/test/sandbox_tests.js new file mode 100644 index 0000000..a1a3589 --- /dev/null +++ b/sandbox-server/test/sandbox_tests.js @@ -0,0 +1,185 @@ +const chai = require('chai') +const expect = chai.expect +const chaiHttp = require('chai-http') +const app = require('../index') + +chai.use(chaiHttp) + +describe('sandbox-server', function(){ + + context.only('homepage, onload', function(){ + + it('Should respond with a status code of 200', function(done){ + chai.request(app) + .get('/') + .end(function(err, res){ + expect(res).to.have.status(200) + done() + }) + }) + it('Should have a Content-Type of text/plain', function(res){ + expect(res).to.have.header('content-type', 'text/plain') + }) + it('Should have a body response that contains the string "Welcome to Sandbox!"', function(res){ + expect(res).to.have.header('Welcome to Sandbox!') + }) + }) + context('Doodads search', function(){ + + it('Should respond with a status code of 200', function(done){ + chai.request(app) + .get('/') + .end(function(err, res){ + expect(res).to.have.status(200) + done() + }) + }) + }) + it('Should have a Content-Type of text/plain', function(res){ + expect(res).to.have.header('content-type', 'text/plain') + }) + it('Should have a body response that contains the string "You searched for: doodads"', function(res){ + expect(res).to.have.header('You searched for: doodads') + }) + }) + + context('Bad request response', function(){ + + it('Should respond with a status code of 400', function(done){ + chai.request(app) + .get('/') + .end(function(err, res){ + expect(res).to.have.status(400) + done() + }) + }) + it('Should have a Content-Type of text/plain', function(){ + expect(res).to.have.header('content-type', 'text/plain') + }) + it('Should have a body response that contains the string "You did not provide a search query term :("', function(){ + + }) + }) + + context('Flying car post', function(){ + + it('Should respond with a status code of 201', function(done){ + chai.request(app) + .get('/') + .end(function(err, res){ + expect(res).to.have.status(201) + done() + }) + }) + it('Should have a Content-Type of text/plain', function(){ + expect(res).to.have.header('content-type', 'text/plain') + }) + it('Should have a body response that contains the string "New thing created: Flying car"', function(){ + + }) + }) + + context('Get some file', function(){ + + it('Should respond with a status code of 200', function(done){ + chai.request(app) + .get('/') + .end(function(err, res){ + expect(res).to.have.status(200) + done() + }) + }) + it('Should have a Content-Type of text/plain', function(){ + expect(res).to.have.header('content-type', 'text/plain') + }) + it('Should have a body response that contains the string "This is a plain text file"', function(){ + + }) + }) + + context('Get html/text', function(){ + + it('Should respond with a status code of 200', function(done){ + chai.request(app) + .get('/') + .end(function(err, res){ + expect(res).to.have.status(200) + done() + }) + }) + it('Should have a Content-Type of html/text', function(){ + expect(res).to.have.header('content-type', 'html/text') + }) + it('Should have a body response that contains the string "This is an HTML file"', function(){ + + }) + }) + + context('Get json data', function(){ + + it('Should respond with a status code of 200', function(done){ + chai.request(app) + .get('/') + .end(function(err, res){ + expect(res).to.have.status(200) + done() + }) + }) + it('Should have a Content-Type of application/json', function(){ + expect(res).to.have.header('content-type', 'application/json') + }) + it('Should have a body response that contains the string "{title: some json data}"', function(){ + + }) + }) + + context('Get old page', function(){ + + it('Should respond with a status code of 301', function(done){ + chai.request(app) + .get('/') + .end(function(err, res){ + expect(res).to.have.status(301) + done() + }) + }) + it('Should contain a location header set localhost:3000/webpage', function(){ + + }) + }) + + context('Post admin only', function(){ + + it('Should respond with a status code of 403', function(done){ + chai.request(app) + .get('/') + .end(function(err, res){ + expect(res).to.have.status(403) + done() + }) + }) + }) + + context('Not a page', function(){ + + it('Should respond with a status code of 404', function(done){ + chai.request(app) + .get('/') + .end(function(err, res){ + expect(res).to.have.status(404) + done() + }) + }) + }) + + context('Server error', function(){ + + it('Should respond with a status code of 500', function(done){ + chai.request(app) + .get('/') + .end(function(err, res){ + expect(res).to.have.status(500) + done() + }) + }) + }) From 1a2f2b8f6cae479000285a5cbf6c06a0eea4f2e5 Mon Sep 17 00:00:00 2001 From: Abraham Ferguson Date: Tue, 21 Mar 2017 10:02:47 -0700 Subject: [PATCH 03/20] modulated routing, completed search query --- sandbox-server/index.js | 7 +++---- sandbox-server/routes/trails.js | 12 ++++++++++++ sandbox-server/test/sandbox_tests.js | 28 +++++++++++----------------- 3 files changed, 26 insertions(+), 21 deletions(-) diff --git a/sandbox-server/index.js b/sandbox-server/index.js index 167e3e8..3198287 100644 --- a/sandbox-server/index.js +++ b/sandbox-server/index.js @@ -5,13 +5,12 @@ const path = require('path') const port = process.env.PORT || 3000 const logger = require('morgan') +const trails = require('./routes/trails') + +server.use('/', trails) server.use(logger("combined")) server.use(express.static(path.join(__dirname, 'public'))) -server.get('/', function(request, response){ - response.send('Hello World') -}) - server.set(port) http.listen(port) diff --git a/sandbox-server/routes/trails.js b/sandbox-server/routes/trails.js index 75fc9ff..b6a2976 100644 --- a/sandbox-server/routes/trails.js +++ b/sandbox-server/routes/trails.js @@ -1 +1,13 @@ const express = require('express') +const router = express.Router() + +router.get('/', (request, response) => { + response.set('content-type', 'text/plain') + response.send('Welcome to Sandbox!') +}) +router.get('/search', (request, response) => { + response.set('content-type', 'text/plain') + response.send("You searched for: 'doodads'") +}) + +module.exports = router diff --git a/sandbox-server/test/sandbox_tests.js b/sandbox-server/test/sandbox_tests.js index a1a3589..7856547 100644 --- a/sandbox-server/test/sandbox_tests.js +++ b/sandbox-server/test/sandbox_tests.js @@ -7,41 +7,34 @@ chai.use(chaiHttp) describe('sandbox-server', function(){ - context.only('homepage, onload', function(){ + context('homepage, onload', function(){ it('Should respond with a status code of 200', function(done){ chai.request(app) .get('/') .end(function(err, res){ expect(res).to.have.status(200) + expect(res.text).to.equal('Welcome to Sandbox!') + expect(res).to.have.header('content-type', 'text/plain; charset=utf-8') done() }) }) - it('Should have a Content-Type of text/plain', function(res){ - expect(res).to.have.header('content-type', 'text/plain') - }) - it('Should have a body response that contains the string "Welcome to Sandbox!"', function(res){ - expect(res).to.have.header('Welcome to Sandbox!') - }) }) - context('Doodads search', function(){ + + context('Doodads search', function(done){ it('Should respond with a status code of 200', function(done){ chai.request(app) - .get('/') + .get('/search') + .query({'q':'doodads'}) .end(function(err, res){ expect(res).to.have.status(200) + expect(res.text).to.equal('You searched for: \'doodads\'') + expect(res).to.have.header('content-type', 'text/plain; charset=utf-8') done() }) }) }) - it('Should have a Content-Type of text/plain', function(res){ - expect(res).to.have.header('content-type', 'text/plain') - }) - it('Should have a body response that contains the string "You searched for: doodads"', function(res){ - expect(res).to.have.header('You searched for: doodads') - }) - }) context('Bad request response', function(){ @@ -57,7 +50,7 @@ describe('sandbox-server', function(){ expect(res).to.have.header('content-type', 'text/plain') }) it('Should have a body response that contains the string "You did not provide a search query term :("', function(){ - + }) }) @@ -183,3 +176,4 @@ describe('sandbox-server', function(){ }) }) }) +}) From 1309d17b67a960e4a40d0e98321ccff8999f837f Mon Sep 17 00:00:00 2001 From: Abraham Ferguson Date: Tue, 21 Mar 2017 14:24:25 -0700 Subject: [PATCH 04/20] completed sandbox api and created postalicious directories --- package.json | 9 +- postalicious/index.js | 0 postalicious/test/post_tests.js | 0 sandbox-server/routes/trails.js | 45 ++++++++- sandbox-server/test/sandbox_tests.js | 143 +++++++++++---------------- 5 files changed, 103 insertions(+), 94 deletions(-) create mode 100644 postalicious/index.js create mode 100644 postalicious/test/post_tests.js diff --git a/package.json b/package.json index 38c2155..1379023 100644 --- a/package.json +++ b/package.json @@ -4,8 +4,10 @@ "description": "A clone of the Postman chrome extension.", "main": "index.js", "scripts": { - "start": "nodemon sandbox-server/index", - "test": "mocha sandbox-server/test/sandbox_tests.js" + "run sandbox-server": "nodemon sandbox-server/index", + "run postalicious": "nodemon postalicious/index", + "test": "mocha sandbox-server/test/sandbox_tests.js", + "testTwo:" : "mocha postalicious/test/post_tests.js" }, "repository": { "type": "git", @@ -22,8 +24,9 @@ "morgan": "^1.7.1" }, "devDependencies": { + "chai": "^3.5.0", "chai-http": "^3.0.0", "mocha": "^3.2.0", - "chai": "^3.5.0" + "pg-promise": "^5.6.4" } } diff --git a/postalicious/index.js b/postalicious/index.js new file mode 100644 index 0000000..e69de29 diff --git a/postalicious/test/post_tests.js b/postalicious/test/post_tests.js new file mode 100644 index 0000000..e69de29 diff --git a/sandbox-server/routes/trails.js b/sandbox-server/routes/trails.js index b6a2976..23d8d4a 100644 --- a/sandbox-server/routes/trails.js +++ b/sandbox-server/routes/trails.js @@ -3,11 +3,50 @@ const router = express.Router() router.get('/', (request, response) => { response.set('content-type', 'text/plain') - response.send('Welcome to Sandbox!') + .send('Welcome to Sandbox!') }) router.get('/search', (request, response) => { - response.set('content-type', 'text/plain') - response.send("You searched for: 'doodads'") + if( request.query.q.length === undefined || request.query.q.length === 0 ){ + response.status(400) + .set('content-type', 'text/plain') + .send("You didn't provide a search query term :(") + }else{ + response.set('content-type', 'text/plain') + .send("You searched for: 'doodads'") + } +}) +router.post('/things', (request, response) => { + response.status(201) + .set('content-type', 'text/plain') + .send("New thing created: flying car!") +}) +router.get('/somefile', (request, response) => { + response.status(200) + .set('content-type', 'text/html') + .send('This is an HTML file') +}) +router.get('/myjsondata', (request, response) => { + if(request.headers.accept === 'application/json'){ + response.status(200) + .set('content-type', 'application/json') + .send(JSON.stringify({"title":"some JSON data"})) + } +}) +router.get('/old-page', (request, response) => { + response.redirect(301,'/newpage') +}) +router.get('/newpage', (request,response) => { + response.status(301) + .set('content-location', 'http://localhost:3000/newpage') + .send('stuff') +}) +router.post('/admin-only', (request, response) => { + response.status(403) + .send('Forbidden') +}) +router.get('/server-error', (request, response) => { + response.status(500) + .send('sumpin broke') }) module.exports = router diff --git a/sandbox-server/test/sandbox_tests.js b/sandbox-server/test/sandbox_tests.js index 7856547..d6ab21e 100644 --- a/sandbox-server/test/sandbox_tests.js +++ b/sandbox-server/test/sandbox_tests.js @@ -5,14 +5,14 @@ const app = require('../index') chai.use(chaiHttp) -describe('sandbox-server', function(){ +describe('sandbox-server', () => { - context('homepage, onload', function(){ + context('homepage, onload', () => { - it('Should respond with a status code of 200', function(done){ + it('Should respond with a status code of 200', (done) => { chai.request(app) .get('/') - .end(function(err, res){ + .end((err, res) => { expect(res).to.have.status(200) expect(res.text).to.equal('Welcome to Sandbox!') expect(res).to.have.header('content-type', 'text/plain; charset=utf-8') @@ -20,14 +20,14 @@ describe('sandbox-server', function(){ }) }) }) - - context('Doodads search', function(done){ - it('Should respond with a status code of 200', function(done){ + context('Doodads search', (done) => { + + it('Should respond with a status code of 200', (done) => { chai.request(app) .get('/search') .query({'q':'doodads'}) - .end(function(err, res){ + .end((err, res) => { expect(res).to.have.status(200) expect(res.text).to.equal('You searched for: \'doodads\'') expect(res).to.have.header('content-type', 'text/plain; charset=utf-8') @@ -36,141 +36,108 @@ describe('sandbox-server', function(){ }) }) - context('Bad request response', function(){ + context('Bad request response', () => { - it('Should respond with a status code of 400', function(done){ + it('Should respond with a status code of 400', (done) => { chai.request(app) - .get('/') - .end(function(err, res){ + .get('/search') + .end((err, res) => { expect(res).to.have.status(400) + expect(res.text).to.equal('You didn\'t provide a search query term :(') + expect(res).to.have.header('content-type', 'text/plain; charset=utf-8') done() }) }) - it('Should have a Content-Type of text/plain', function(){ - expect(res).to.have.header('content-type', 'text/plain') - }) - it('Should have a body response that contains the string "You did not provide a search query term :("', function(){ - - }) }) - context('Flying car post', function(){ + context('Flying car post', () => { - it('Should respond with a status code of 201', function(done){ + it('Should respond with a status code of 201', (done) => { chai.request(app) - .get('/') - .end(function(err, res){ + .post('/things') + .send({'New thing created': 'flying car'}) + .end((err, res) => { expect(res).to.have.status(201) + expect(res.text).to.equal('New thing created: flying car!') + expect(res).to.have.header('content-type', 'text/plain; charset=utf-8') done() }) }) - it('Should have a Content-Type of text/plain', function(){ - expect(res).to.have.header('content-type', 'text/plain') - }) - it('Should have a body response that contains the string "New thing created: Flying car"', function(){ - - }) - }) - - context('Get some file', function(){ - - it('Should respond with a status code of 200', function(done){ - chai.request(app) - .get('/') - .end(function(err, res){ - expect(res).to.have.status(200) - done() - }) - }) - it('Should have a Content-Type of text/plain', function(){ - expect(res).to.have.header('content-type', 'text/plain') - }) - it('Should have a body response that contains the string "This is a plain text file"', function(){ - - }) }) - context('Get html/text', function(){ + context('Get some file', () => { - it('Should respond with a status code of 200', function(done){ + it('Should respond with a status code of 200', (done) => { chai.request(app) - .get('/') - .end(function(err, res){ + .get('/somefile') + .end((err, res) => { expect(res).to.have.status(200) + expect(res.text).to.equal('This is an HTML file') + expect(res).to.have.header('content-type', 'text/html; charset=utf-8') done() }) }) - it('Should have a Content-Type of html/text', function(){ - expect(res).to.have.header('content-type', 'html/text') - }) - it('Should have a body response that contains the string "This is an HTML file"', function(){ - - }) }) - context('Get json data', function(){ + context('Get json data', () => { - it('Should respond with a status code of 200', function(done){ + it('Should respond with a status code of 200', (done) => { chai.request(app) - .get('/') - .end(function(err, res){ + .get('/myjsondata') + .set('accept', 'application/json') + .end((err, res) => { expect(res).to.have.status(200) + expect(res.text).to.equal('{"title":"some JSON data"}') + expect(res).to.have.header('content-type', 'application/json; charset=utf-8') done() }) }) - it('Should have a Content-Type of application/json', function(){ - expect(res).to.have.header('content-type', 'application/json') - }) - it('Should have a body response that contains the string "{title: some json data}"', function(){ - - }) }) - context('Get old page', function(){ + context('Get old page', () => { - it('Should respond with a status code of 301', function(done){ + it('Should respond with a status code of 301', (done) => { chai.request(app) - .get('/') - .end(function(err, res){ - expect(res).to.have.status(301) + .get('/old-page') + .end((err, res) => { + expect(res.statusCode).to.eql(301) + expect(res.headers["content-location"]).to.equal('http://localhost:3000/newpage') done() }) }) - it('Should contain a location header set localhost:3000/webpage', function(){ - - }) }) - context('Post admin only', function(){ + context('Post admin only', () => { - it('Should respond with a status code of 403', function(done){ + it('Should respond with a status code of 403', (done) => { chai.request(app) - .get('/') - .end(function(err, res){ - expect(res).to.have.status(403) + .post('/admin-only') + .send({'stuff': 'all'}) + .end((err, res) => { + expect(res.statusCode).to.eql(403) done() }) }) }) - context('Not a page', function(){ + context('Not a page', () => { - it('Should respond with a status code of 404', function(done){ + it('Should respond with a status code of 404', (done) => { chai.request(app) - .get('/') - .end(function(err, res){ - expect(res).to.have.status(404) + .get('/not-a-page') + .end((err, res) => { + expect(res.statusCode).to.eql(404) done() }) }) }) - context('Server error', function(){ + context.only('Server error', () => { - it('Should respond with a status code of 500', function(done){ + it('Should respond with a status code of 500', (done) => { chai.request(app) - .get('/') - .end(function(err, res){ + .get('/server-error') + .end((err, res) => { expect(res).to.have.status(500) done() }) From 9ad607ed2f11a8105e3cb246b386a016e1dc7276 Mon Sep 17 00:00:00 2001 From: lizzkats Date: Tue, 21 Mar 2017 14:41:18 -0700 Subject: [PATCH 05/20] added start scripts --- package.json | 2 +- postalicious/index.js | 19 ++++ sandbox-server/index.js | 7 +- sandbox-server/test/sandbox_tests.js | 163 +++++++++++++++++---------- 4 files changed, 125 insertions(+), 66 deletions(-) diff --git a/package.json b/package.json index 1379023..59ea441 100644 --- a/package.json +++ b/package.json @@ -5,7 +5,7 @@ "main": "index.js", "scripts": { "run sandbox-server": "nodemon sandbox-server/index", - "run postalicious": "nodemon postalicious/index", + "pl": "nodemon postalicious/index", "test": "mocha sandbox-server/test/sandbox_tests.js", "testTwo:" : "mocha postalicious/test/post_tests.js" }, diff --git a/postalicious/index.js b/postalicious/index.js index e69de29..7050c1c 100644 --- a/postalicious/index.js +++ b/postalicious/index.js @@ -0,0 +1,19 @@ +const express = require('express') +const server = express() +const http = require('http').createServer(server) +const path = require('path') +const port = process.env.PORT || 3001 +const logger = require('morgan') + +server.use(logger("combined")) +server.use(express.static(path.join(__dirname, 'public'))) + +server.get('/', function(request, response){ + response.send('Hello World') +}) + +server.set(port) + +http.listen(port) + +module.exports = server diff --git a/sandbox-server/index.js b/sandbox-server/index.js index 3198287..0a9993d 100644 --- a/sandbox-server/index.js +++ b/sandbox-server/index.js @@ -5,12 +5,13 @@ const path = require('path') const port = process.env.PORT || 3000 const logger = require('morgan') -const trails = require('./routes/trails') - -server.use('/', trails) server.use(logger("combined")) server.use(express.static(path.join(__dirname, 'public'))) +server.get('/', function(request, response){ + response.send('Welcome to the sandbox!') +}) + server.set(port) http.listen(port) diff --git a/sandbox-server/test/sandbox_tests.js b/sandbox-server/test/sandbox_tests.js index d6ab21e..d07be6b 100644 --- a/sandbox-server/test/sandbox_tests.js +++ b/sandbox-server/test/sandbox_tests.js @@ -5,142 +5,181 @@ const app = require('../index') chai.use(chaiHttp) -describe('sandbox-server', () => { +describe('sandbox-server', function(){ - context('homepage, onload', () => { + context.only('homepage, onload', function(){ - it('Should respond with a status code of 200', (done) => { + it('Should respond with a status code of 200', function(done){ chai.request(app) .get('/') - .end((err, res) => { + .end(function(err, res){ expect(res).to.have.status(200) - expect(res.text).to.equal('Welcome to Sandbox!') - expect(res).to.have.header('content-type', 'text/plain; charset=utf-8') done() }) }) + it('Should have a Content-Type of text/plain', function(res){ + expect(res).to.have.header('content-type', 'text/plain') + }) + it('Should have a body response that contains the string "Welcome to Sandbox!"', function(res){ + expect(res).to.have.header('Welcome to Sandbox!') + }) }) + context('Doodads search', function(){ - context('Doodads search', (done) => { - - it('Should respond with a status code of 200', (done) => { + it('Should respond with a status code of 200', function(done){ chai.request(app) - .get('/search') - .query({'q':'doodads'}) - .end((err, res) => { + .get('/') + .end(function(err, res){ expect(res).to.have.status(200) - expect(res.text).to.equal('You searched for: \'doodads\'') - expect(res).to.have.header('content-type', 'text/plain; charset=utf-8') done() }) }) }) + it('Should have a Content-Type of text/plain', function(res){ + expect(res).to.have.header('content-type', 'text/plain') + }) + it('Should have a body response that contains the string "You searched for: doodads"', function(res){ + expect(res).to.have.header('You searched for: doodads') + }) + }) - context('Bad request response', () => { + context('Bad request response', function(){ - it('Should respond with a status code of 400', (done) => { + it('Should respond with a status code of 400', function(done){ chai.request(app) - .get('/search') - .end((err, res) => { + .get('/') + .end(function(err, res){ expect(res).to.have.status(400) - expect(res.text).to.equal('You didn\'t provide a search query term :(') - expect(res).to.have.header('content-type', 'text/plain; charset=utf-8') done() }) }) + it('Should have a Content-Type of text/plain', function(){ + expect(res).to.have.header('content-type', 'text/plain') + }) + it('Should have a body response that contains the string "You did not provide a search query term :("', function(){ + + }) }) - context('Flying car post', () => { + context('Flying car post', function(){ - it('Should respond with a status code of 201', (done) => { + it('Should respond with a status code of 201', function(done){ chai.request(app) - .post('/things') - .send({'New thing created': 'flying car'}) - .end((err, res) => { + .get('/') + .end(function(err, res){ expect(res).to.have.status(201) - expect(res.text).to.equal('New thing created: flying car!') - expect(res).to.have.header('content-type', 'text/plain; charset=utf-8') done() }) }) + it('Should have a Content-Type of text/plain', function(){ + expect(res).to.have.header('content-type', 'text/plain') + }) + it('Should have a body response that contains the string "New thing created: Flying car"', function(){ + + }) }) - context('Get some file', () => { + context('Get some file', function(){ - it('Should respond with a status code of 200', (done) => { + it('Should respond with a status code of 200', function(done){ chai.request(app) - .get('/somefile') - .end((err, res) => { + .get('/') + .end(function(err, res){ expect(res).to.have.status(200) - expect(res.text).to.equal('This is an HTML file') - expect(res).to.have.header('content-type', 'text/html; charset=utf-8') done() }) }) + it('Should have a Content-Type of text/plain', function(){ + expect(res).to.have.header('content-type', 'text/plain') + }) + it('Should have a body response that contains the string "This is a plain text file"', function(){ + + }) }) - context('Get json data', () => { + context('Get html/text', function(){ - it('Should respond with a status code of 200', (done) => { + it('Should respond with a status code of 200', function(done){ chai.request(app) - .get('/myjsondata') - .set('accept', 'application/json') - .end((err, res) => { + .get('/') + .end(function(err, res){ expect(res).to.have.status(200) - expect(res.text).to.equal('{"title":"some JSON data"}') - expect(res).to.have.header('content-type', 'application/json; charset=utf-8') done() }) }) + it('Should have a Content-Type of html/text', function(){ + expect(res).to.have.header('content-type', 'html/text') + }) + it('Should have a body response that contains the string "This is an HTML file"', function(){ + + }) + }) + + context('Get json data', function(){ + + it('Should respond with a status code of 200', function(done){ + chai.request(app) + .get('/') + .end(function(err, res){ + expect(res).to.have.status(200) + done() + }) + }) + it('Should have a Content-Type of application/json', function(){ + expect(res).to.have.header('content-type', 'application/json') + }) + it('Should have a body response that contains the string "{title: some json data}"', function(){ + + }) }) - context('Get old page', () => { + context('Get old page', function(){ - it('Should respond with a status code of 301', (done) => { + it('Should respond with a status code of 301', function(done){ chai.request(app) - .get('/old-page') - .end((err, res) => { - expect(res.statusCode).to.eql(301) - expect(res.headers["content-location"]).to.equal('http://localhost:3000/newpage') + .get('/') + .end(function(err, res){ + expect(res).to.have.status(301) done() }) }) + it('Should contain a location header set localhost:3000/webpage', function(){ + + }) }) - context('Post admin only', () => { + context('Post admin only', function(){ - it('Should respond with a status code of 403', (done) => { + it('Should respond with a status code of 403', function(done){ chai.request(app) - .post('/admin-only') - .send({'stuff': 'all'}) - .end((err, res) => { - expect(res.statusCode).to.eql(403) + .get('/') + .end(function(err, res){ + expect(res).to.have.status(403) done() }) }) }) - context('Not a page', () => { + context('Not a page', function(){ - it('Should respond with a status code of 404', (done) => { + it('Should respond with a status code of 404', function(done){ chai.request(app) - .get('/not-a-page') - .end((err, res) => { - expect(res.statusCode).to.eql(404) + .get('/') + .end(function(err, res){ + expect(res).to.have.status(404) done() }) }) }) - context.only('Server error', () => { + context('Server error', function(){ - it('Should respond with a status code of 500', (done) => { + it('Should respond with a status code of 500', function(done){ chai.request(app) - .get('/server-error') - .end((err, res) => { + .get('/') + .end(function(err, res){ expect(res).to.have.status(500) done() }) }) }) -}) From 5ece4420e2650d6606e97b56cb5de2a23c23d504 Mon Sep 17 00:00:00 2001 From: lizzkats Date: Tue, 21 Mar 2017 14:44:05 -0700 Subject: [PATCH 06/20] adding untracked file --- postalicious/routes/form_routes.js | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 postalicious/routes/form_routes.js diff --git a/postalicious/routes/form_routes.js b/postalicious/routes/form_routes.js new file mode 100644 index 0000000..49caaaa --- /dev/null +++ b/postalicious/routes/form_routes.js @@ -0,0 +1,2 @@ +const express = require('express') +const router = expressRouter From fd20a04eea1a23780b43373f540c3dc248d57d30 Mon Sep 17 00:00:00 2001 From: lizzkats Date: Tue, 21 Mar 2017 14:44:33 -0700 Subject: [PATCH 07/20] gitignore --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 3c3629e..424429e 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ node_modules +*log From cea430c4da238aaf9905ac5c515465ce503562d8 Mon Sep 17 00:00:00 2001 From: lizzkats Date: Wed, 22 Mar 2017 09:13:39 -0700 Subject: [PATCH 08/20] added basic form on front end --- package.json | 3 +- postalicious/index.js | 5 ++ postalicious/routes/form_routes.js | 2 +- postalicious/stylesheets/style.css | 31 ++++++++++++ postalicious/views/index.html | 80 ++++++++++++++++++++++++++++++ 5 files changed, 119 insertions(+), 2 deletions(-) create mode 100644 postalicious/stylesheets/style.css create mode 100644 postalicious/views/index.html diff --git a/package.json b/package.json index 59ea441..e07fc18 100644 --- a/package.json +++ b/package.json @@ -7,7 +7,7 @@ "run sandbox-server": "nodemon sandbox-server/index", "pl": "nodemon postalicious/index", "test": "mocha sandbox-server/test/sandbox_tests.js", - "testTwo:" : "mocha postalicious/test/post_tests.js" + "testTwo:": "mocha postalicious/test/post_tests.js" }, "repository": { "type": "git", @@ -20,6 +20,7 @@ }, "homepage": "https://github.com/lizzkats/Postalicious#readme", "dependencies": { + "body-parser": "^1.17.1", "express": "^4.15.2", "morgan": "^1.7.1" }, diff --git a/postalicious/index.js b/postalicious/index.js index 7050c1c..701f0b0 100644 --- a/postalicious/index.js +++ b/postalicious/index.js @@ -5,6 +5,11 @@ const path = require('path') const port = process.env.PORT || 3001 const logger = require('morgan') +app.set('views', path.join(__dirname, 'views')) +app.set('view engine', 'html') + +server.use(bodyParser.json()) +server.use(bodyParser.urlencoded({extended: true})) server.use(logger("combined")) server.use(express.static(path.join(__dirname, 'public'))) diff --git a/postalicious/routes/form_routes.js b/postalicious/routes/form_routes.js index 49caaaa..337e147 100644 --- a/postalicious/routes/form_routes.js +++ b/postalicious/routes/form_routes.js @@ -1,2 +1,2 @@ const express = require('express') -const router = expressRouter +const router = express.Router() diff --git a/postalicious/stylesheets/style.css b/postalicious/stylesheets/style.css new file mode 100644 index 0000000..42895b0 --- /dev/null +++ b/postalicious/stylesheets/style.css @@ -0,0 +1,31 @@ + +.title { + background-color: grey; +} + +.method-input, .host-input { + margin-bottom: 10px; + width: 275px; + height: 30px; + background-color: lightgrey; +} + +.build-request { + height: 35px; + width: 180px; +} + +.build-send { + height: 35px; + width: 180px; +} + +.body-box { + height: 100px; + width: 200px; +} + +.request-body-box, .response-body-box { + width: 500px; + height: 250px; +} diff --git a/postalicious/views/index.html b/postalicious/views/index.html new file mode 100644 index 0000000..d65d361 --- /dev/null +++ b/postalicious/views/index.html @@ -0,0 +1,80 @@ + + + + + Postalicious + + + + +
+
+
Postalicious
+
+
+
+ Method + +
+ Host + +
+
+
+
+ Query Parameters +
+
+ + + +
+
+ + + +
+
+
+
+ Headers +
+
+ + + +
+
+ + + +
+
+
+
+ Body + +
+
+
+
+
+
+ +
+
+
+
+ +
+
+
+
+
+ + +
+
+ + + From 8df60d076ce29fbaa7aa070468bc7744314d7273 Mon Sep 17 00:00:00 2001 From: Abraham Ferguson Date: Wed, 22 Mar 2017 11:56:09 -0700 Subject: [PATCH 09/20] established form data extraction --- package.json | 2 +- postalicious/index.js | 14 ++-- postalicious/methods.js | 11 +++ postalicious/public/index.html | 80 +++++++++++++++++++ .../{ => public}/stylesheets/style.css | 0 postalicious/routes/form_routes.js | 12 +++ postalicious/views/index.html | 12 +-- sandbox-server/api-methods/methods.js | 11 +++ 8 files changed, 127 insertions(+), 15 deletions(-) create mode 100644 postalicious/methods.js create mode 100644 postalicious/public/index.html rename postalicious/{ => public}/stylesheets/style.css (100%) create mode 100644 sandbox-server/api-methods/methods.js diff --git a/package.json b/package.json index e07fc18..00c7205 100644 --- a/package.json +++ b/package.json @@ -4,7 +4,7 @@ "description": "A clone of the Postman chrome extension.", "main": "index.js", "scripts": { - "run sandbox-server": "nodemon sandbox-server/index", + "sandbox-server": "nodemon sandbox-server/index", "pl": "nodemon postalicious/index", "test": "mocha sandbox-server/test/sandbox_tests.js", "testTwo:": "mocha postalicious/test/post_tests.js" diff --git a/postalicious/index.js b/postalicious/index.js index 701f0b0..75e43a2 100644 --- a/postalicious/index.js +++ b/postalicious/index.js @@ -2,20 +2,18 @@ const express = require('express') const server = express() const http = require('http').createServer(server) const path = require('path') -const port = process.env.PORT || 3001 const logger = require('morgan') +const bodyParser = require('body-parser') -app.set('views', path.join(__dirname, 'views')) -app.set('view engine', 'html') +const port = process.env.PORT || 3001 +const index = require('./routes/form_routes.js') -server.use(bodyParser.json()) +server.use(bodyParser.json({ type: 'application/json' })) server.use(bodyParser.urlencoded({extended: true})) -server.use(logger("combined")) server.use(express.static(path.join(__dirname, 'public'))) +server.use('/', index) -server.get('/', function(request, response){ - response.send('Hello World') -}) +server.use(logger("combined")) server.set(port) diff --git a/postalicious/methods.js b/postalicious/methods.js new file mode 100644 index 0000000..12c614b --- /dev/null +++ b/postalicious/methods.js @@ -0,0 +1,11 @@ +const pgp = require('pg-promise')() +const db = pgp({thing: 'sandbox'}) + + +const buildRequest = (data) => { + let something = data + // console.log(data); + return db.any(something) +} + +module.exports = { buildRequest } diff --git a/postalicious/public/index.html b/postalicious/public/index.html new file mode 100644 index 0000000..3bda5dc --- /dev/null +++ b/postalicious/public/index.html @@ -0,0 +1,80 @@ + + + + + Postalicious + + + + +
+
+
Postalicious
+
+
+
+ Method + +
+ Host + +
+
+
+
+ Query Parameters +
+
+ + + +
+
+ + + +
+
+
+
+ Headers +
+
+ + + +
+
+ + + +
+
+
+
+ Body + +
+
+
+
+
+
+
+
+ +
+
+
+
+
+
REQUEST
+
RESPONSE
+
+
+ +
+
+
+ + diff --git a/postalicious/stylesheets/style.css b/postalicious/public/stylesheets/style.css similarity index 100% rename from postalicious/stylesheets/style.css rename to postalicious/public/stylesheets/style.css diff --git a/postalicious/routes/form_routes.js b/postalicious/routes/form_routes.js index 337e147..6cdd8f9 100644 --- a/postalicious/routes/form_routes.js +++ b/postalicious/routes/form_routes.js @@ -1,2 +1,14 @@ const express = require('express') const router = express.Router() + +const place = require('../methods') + +router.post('/', (request, response) => { + // console.log(request.body) + place.buildRequest(request.body) + .then(_ => console.log('done')) + response.send(request.body) +}) + + +module.exports = router diff --git a/postalicious/views/index.html b/postalicious/views/index.html index d65d361..8089299 100644 --- a/postalicious/views/index.html +++ b/postalicious/views/index.html @@ -3,12 +3,12 @@ Postalicious - +
-
+
Postalicious
@@ -60,19 +60,19 @@
- +
- +
- - + +
diff --git a/sandbox-server/api-methods/methods.js b/sandbox-server/api-methods/methods.js new file mode 100644 index 0000000..1eb10e9 --- /dev/null +++ b/sandbox-server/api-methods/methods.js @@ -0,0 +1,11 @@ +const pgp = require('pg-promise') +const db = pgp('sandBox') + +const arr = ['doodads'] + +const finder = (str) => { + console.log('herere') + console.log(str) +} + +module.exports = { finder } From 9d531f89b796c4c4e71bc0e45751f7ddfc9ea8d3 Mon Sep 17 00:00:00 2001 From: Abraham Ferguson Date: Wed, 22 Mar 2017 17:13:26 -0700 Subject: [PATCH 10/20] added css styling, layout corrections, data retrieval --- postalicious/methods.js | 11 --- postalicious/public/index.html | 116 ++++++++++++++++------------- postalicious/routes/form_routes.js | 6 +- postalicious/views/index.html | 80 -------------------- 4 files changed, 67 insertions(+), 146 deletions(-) delete mode 100644 postalicious/methods.js delete mode 100644 postalicious/views/index.html diff --git a/postalicious/methods.js b/postalicious/methods.js deleted file mode 100644 index 12c614b..0000000 --- a/postalicious/methods.js +++ /dev/null @@ -1,11 +0,0 @@ -const pgp = require('pg-promise')() -const db = pgp({thing: 'sandbox'}) - - -const buildRequest = (data) => { - let something = data - // console.log(data); - return db.any(something) -} - -module.exports = { buildRequest } diff --git a/postalicious/public/index.html b/postalicious/public/index.html index 3bda5dc..fe06d6e 100644 --- a/postalicious/public/index.html +++ b/postalicious/public/index.html @@ -7,74 +7,86 @@ -
+
-
Postalicious
-
-
-
+
Postalicious
+
+
+
Method - -
- Host - -
-
-
-
- Query Parameters -
-
- - - -
-
+ +
+
+ Host + +
+
+
+ Query Parameters +
+
+ + + +
+
-
+
Headers -
-
- - - -
-
- - - +
+
+ + + +
+
+ + + +
+
+
+ Body +
-
- Body - -
-
-
-
-
-
- +
+
+
+ +
+
+
+ +
+
+
+
+
+ REQUEST +
+
+
+
+
+
+
RESPONSE
+
+
-
-
-
-
REQUEST
-
RESPONSE
-
-
- -
-
+ diff --git a/postalicious/routes/form_routes.js b/postalicious/routes/form_routes.js index 6cdd8f9..cd2b7b2 100644 --- a/postalicious/routes/form_routes.js +++ b/postalicious/routes/form_routes.js @@ -1,12 +1,12 @@ const express = require('express') const router = express.Router() -const place = require('../methods') +// const place = require('../public/methods') router.post('/', (request, response) => { // console.log(request.body) - place.buildRequest(request.body) - .then(_ => console.log('done')) + // place.buildRequest(request.body) + // .then(_ => console.log('done')) response.send(request.body) }) diff --git a/postalicious/views/index.html b/postalicious/views/index.html deleted file mode 100644 index 8089299..0000000 --- a/postalicious/views/index.html +++ /dev/null @@ -1,80 +0,0 @@ - - - - - Postalicious - - - - -
-
-
Postalicious
-
-
-
- Method - -
- Host - -
-
-
-
- Query Parameters -
-
- - - -
-
- - - -
-
-
-
- Headers -
-
- - - -
-
- - - -
-
-
-
- Body - -
-
-
-
-
-
- -
-
-
-
- -
-
-
-
-
- - -
-
- - - From 983c5cd0c1ee083104bf7edb47c1cd3ac0cb5eaa Mon Sep 17 00:00:00 2001 From: Abraham Ferguson Date: Thu, 23 Mar 2017 09:03:10 -0700 Subject: [PATCH 11/20] missing files --- postalicious/public/index.html | 2 +- sandbox-server/test/sandbox_tests.js | 163 ++++++++++----------------- 2 files changed, 63 insertions(+), 102 deletions(-) diff --git a/postalicious/public/index.html b/postalicious/public/index.html index fe06d6e..daeb6d5 100644 --- a/postalicious/public/index.html +++ b/postalicious/public/index.html @@ -80,7 +80,7 @@
-
+
RESPONSE
diff --git a/sandbox-server/test/sandbox_tests.js b/sandbox-server/test/sandbox_tests.js index d07be6b..d6ab21e 100644 --- a/sandbox-server/test/sandbox_tests.js +++ b/sandbox-server/test/sandbox_tests.js @@ -5,181 +5,142 @@ const app = require('../index') chai.use(chaiHttp) -describe('sandbox-server', function(){ +describe('sandbox-server', () => { - context.only('homepage, onload', function(){ + context('homepage, onload', () => { - it('Should respond with a status code of 200', function(done){ + it('Should respond with a status code of 200', (done) => { chai.request(app) .get('/') - .end(function(err, res){ + .end((err, res) => { expect(res).to.have.status(200) + expect(res.text).to.equal('Welcome to Sandbox!') + expect(res).to.have.header('content-type', 'text/plain; charset=utf-8') done() }) }) - it('Should have a Content-Type of text/plain', function(res){ - expect(res).to.have.header('content-type', 'text/plain') - }) - it('Should have a body response that contains the string "Welcome to Sandbox!"', function(res){ - expect(res).to.have.header('Welcome to Sandbox!') - }) }) - context('Doodads search', function(){ - it('Should respond with a status code of 200', function(done){ + context('Doodads search', (done) => { + + it('Should respond with a status code of 200', (done) => { chai.request(app) - .get('/') - .end(function(err, res){ + .get('/search') + .query({'q':'doodads'}) + .end((err, res) => { expect(res).to.have.status(200) + expect(res.text).to.equal('You searched for: \'doodads\'') + expect(res).to.have.header('content-type', 'text/plain; charset=utf-8') done() }) }) }) - it('Should have a Content-Type of text/plain', function(res){ - expect(res).to.have.header('content-type', 'text/plain') - }) - it('Should have a body response that contains the string "You searched for: doodads"', function(res){ - expect(res).to.have.header('You searched for: doodads') - }) - }) - context('Bad request response', function(){ + context('Bad request response', () => { - it('Should respond with a status code of 400', function(done){ + it('Should respond with a status code of 400', (done) => { chai.request(app) - .get('/') - .end(function(err, res){ + .get('/search') + .end((err, res) => { expect(res).to.have.status(400) + expect(res.text).to.equal('You didn\'t provide a search query term :(') + expect(res).to.have.header('content-type', 'text/plain; charset=utf-8') done() }) }) - it('Should have a Content-Type of text/plain', function(){ - expect(res).to.have.header('content-type', 'text/plain') - }) - it('Should have a body response that contains the string "You did not provide a search query term :("', function(){ - - }) }) - context('Flying car post', function(){ + context('Flying car post', () => { - it('Should respond with a status code of 201', function(done){ + it('Should respond with a status code of 201', (done) => { chai.request(app) - .get('/') - .end(function(err, res){ + .post('/things') + .send({'New thing created': 'flying car'}) + .end((err, res) => { expect(res).to.have.status(201) + expect(res.text).to.equal('New thing created: flying car!') + expect(res).to.have.header('content-type', 'text/plain; charset=utf-8') done() }) }) - it('Should have a Content-Type of text/plain', function(){ - expect(res).to.have.header('content-type', 'text/plain') - }) - it('Should have a body response that contains the string "New thing created: Flying car"', function(){ - - }) }) - context('Get some file', function(){ + context('Get some file', () => { - it('Should respond with a status code of 200', function(done){ + it('Should respond with a status code of 200', (done) => { chai.request(app) - .get('/') - .end(function(err, res){ + .get('/somefile') + .end((err, res) => { expect(res).to.have.status(200) + expect(res.text).to.equal('This is an HTML file') + expect(res).to.have.header('content-type', 'text/html; charset=utf-8') done() }) }) - it('Should have a Content-Type of text/plain', function(){ - expect(res).to.have.header('content-type', 'text/plain') - }) - it('Should have a body response that contains the string "This is a plain text file"', function(){ - - }) }) - context('Get html/text', function(){ + context('Get json data', () => { - it('Should respond with a status code of 200', function(done){ + it('Should respond with a status code of 200', (done) => { chai.request(app) - .get('/') - .end(function(err, res){ + .get('/myjsondata') + .set('accept', 'application/json') + .end((err, res) => { expect(res).to.have.status(200) + expect(res.text).to.equal('{"title":"some JSON data"}') + expect(res).to.have.header('content-type', 'application/json; charset=utf-8') done() }) }) - it('Should have a Content-Type of html/text', function(){ - expect(res).to.have.header('content-type', 'html/text') - }) - it('Should have a body response that contains the string "This is an HTML file"', function(){ - - }) - }) - - context('Get json data', function(){ - - it('Should respond with a status code of 200', function(done){ - chai.request(app) - .get('/') - .end(function(err, res){ - expect(res).to.have.status(200) - done() - }) - }) - it('Should have a Content-Type of application/json', function(){ - expect(res).to.have.header('content-type', 'application/json') - }) - it('Should have a body response that contains the string "{title: some json data}"', function(){ - - }) }) - context('Get old page', function(){ + context('Get old page', () => { - it('Should respond with a status code of 301', function(done){ + it('Should respond with a status code of 301', (done) => { chai.request(app) - .get('/') - .end(function(err, res){ - expect(res).to.have.status(301) + .get('/old-page') + .end((err, res) => { + expect(res.statusCode).to.eql(301) + expect(res.headers["content-location"]).to.equal('http://localhost:3000/newpage') done() }) }) - it('Should contain a location header set localhost:3000/webpage', function(){ - - }) }) - context('Post admin only', function(){ + context('Post admin only', () => { - it('Should respond with a status code of 403', function(done){ + it('Should respond with a status code of 403', (done) => { chai.request(app) - .get('/') - .end(function(err, res){ - expect(res).to.have.status(403) + .post('/admin-only') + .send({'stuff': 'all'}) + .end((err, res) => { + expect(res.statusCode).to.eql(403) done() }) }) }) - context('Not a page', function(){ + context('Not a page', () => { - it('Should respond with a status code of 404', function(done){ + it('Should respond with a status code of 404', (done) => { chai.request(app) - .get('/') - .end(function(err, res){ - expect(res).to.have.status(404) + .get('/not-a-page') + .end((err, res) => { + expect(res.statusCode).to.eql(404) done() }) }) }) - context('Server error', function(){ + context.only('Server error', () => { - it('Should respond with a status code of 500', function(done){ + it('Should respond with a status code of 500', (done) => { chai.request(app) - .get('/') - .end(function(err, res){ + .get('/server-error') + .end((err, res) => { expect(res).to.have.status(500) done() }) }) }) +}) From 9a0d9a34c32e371b6a57506cb617b4eebe6b3d4d Mon Sep 17 00:00:00 2001 From: Abraham Ferguson Date: Thu, 23 Mar 2017 09:24:34 -0700 Subject: [PATCH 12/20] method file --- postalicious/public/methods.js | 35 ++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 postalicious/public/methods.js diff --git a/postalicious/public/methods.js b/postalicious/public/methods.js new file mode 100644 index 0000000..95ff543 --- /dev/null +++ b/postalicious/public/methods.js @@ -0,0 +1,35 @@ +// const pgp = require('pg-promise')() +// const db = pgp({thing: 'sandbox'}) + +// const buildRequest = (data) => { +// let something = data +// // console.log(data); +// return db.any(something) +// } + +//search uriencoded +//use new header +//search fetch +//construct url + +function construct(event) { + event.preventDefault() + const method = document.getElementsByClassName("method-input")[0].value + const host = document.getElementsByClassName("host-input")[0].value + const queryParamArray = [] + const docKeyLength = document.getElementsByClassName("key").length + const headersArray = [] + const docValLength = document.getElementsByClassName("value").length + for (var i = 0; i < docKeyLength; i++) { + queryParamArray.push(document.getElementsByClassName("key")[i].value) + } + for (var i = 0; i < docValLength; i++) { + headersArray.push(document.getElementsByClassName("value")[i].value) + } + console.log(method); + document.getElementById("request_content").innerText = method + ' ' + host + document.getElementById("request_content2").innerText = queryParamArray + document.getElementById("request_content3").innerText = headersArray +} + +// module.exports = { buildRequest, construct } From a15c88e68eac4a12d9d650864dfe4745cbe0c4e7 Mon Sep 17 00:00:00 2001 From: lizzkats Date: Thu, 23 Mar 2017 13:53:54 -0700 Subject: [PATCH 13/20] adds some UI for requests --- postalicious/public/index.html | 12 +++---- postalicious/public/methods.js | 52 +++++++++++++++--------------- postalicious/stylesheets/style.css | 31 ++++++++++++++++++ 3 files changed, 63 insertions(+), 32 deletions(-) create mode 100644 postalicious/stylesheets/style.css diff --git a/postalicious/public/index.html b/postalicious/public/index.html index daeb6d5..3ba218c 100644 --- a/postalicious/public/index.html +++ b/postalicious/public/index.html @@ -43,14 +43,14 @@ Headers
- - - + + +
- - - + + +
diff --git a/postalicious/public/methods.js b/postalicious/public/methods.js index 95ff543..c6faf78 100644 --- a/postalicious/public/methods.js +++ b/postalicious/public/methods.js @@ -1,35 +1,35 @@ -// const pgp = require('pg-promise')() -// const db = pgp({thing: 'sandbox'}) - -// const buildRequest = (data) => { -// let something = data -// // console.log(data); -// return db.any(something) -// } - //search uriencoded //use new header //search fetch //construct url +const protocol = 'http/1.1' +const method = document.getElementsByClassName("method-input")[0].value +const docKeyLength = document.getElementsByClassName("key").length +const docValLength = document.getElementsByClassName("value").length +const headerOptions = document.getElementsByClassName('daheaders') +const headerValue = document.getElementsByClassName('select') + +const headers = new Headers() function construct(event) { - event.preventDefault() - const method = document.getElementsByClassName("method-input")[0].value const host = document.getElementsByClassName("host-input")[0].value - const queryParamArray = [] - const docKeyLength = document.getElementsByClassName("key").length - const headersArray = [] - const docValLength = document.getElementsByClassName("value").length - for (var i = 0; i < docKeyLength; i++) { - queryParamArray.push(document.getElementsByClassName("key")[i].value) - } - for (var i = 0; i < docValLength; i++) { - headersArray.push(document.getElementsByClassName("value")[i].value) + const keyHeader1 = document.getElementById('header-key1').value + const valueHeader1 = document.getElementById('header-value1').value + // headers.append(keyHeader1, valueHeader1) + console.log('keyheader', valueHeader1, keyHeader1); + headers.append(keyHeader1, valueHeader1) + console.log(headers.get('content-type'), '=======', headers.headers); + event.preventDefault() + let url = '' + url = host + '?' + for (var i = 0; i < docKeyLength - 1; i++) { + if(document.getElementsByClassName("key")[i].value.length !== 0){ + url += document.getElementsByClassName("key")[i].value + '=' + document.getElementsByClassName("value")[i].value + '&' + } } - console.log(method); - document.getElementById("request_content").innerText = method + ' ' + host - document.getElementById("request_content2").innerText = queryParamArray - document.getElementById("request_content3").innerText = headersArray + url = url.substring(0, url.length - 1) + console.log('url=====', url) + document.getElementById("request_content").innerText = method + ' ' + protocol + document.getElementById("request_content2").innerText = url + // document.getElementById("request_content3").innerText = headersArray } - -// module.exports = { buildRequest, construct } diff --git a/postalicious/stylesheets/style.css b/postalicious/stylesheets/style.css new file mode 100644 index 0000000..42895b0 --- /dev/null +++ b/postalicious/stylesheets/style.css @@ -0,0 +1,31 @@ + +.title { + background-color: grey; +} + +.method-input, .host-input { + margin-bottom: 10px; + width: 275px; + height: 30px; + background-color: lightgrey; +} + +.build-request { + height: 35px; + width: 180px; +} + +.build-send { + height: 35px; + width: 180px; +} + +.body-box { + height: 100px; + width: 200px; +} + +.request-body-box, .response-body-box { + width: 500px; + height: 250px; +} From caedce80fd7fc86ed3259ca50451fce43fb24927 Mon Sep 17 00:00:00 2001 From: Abraham Ferguson Date: Thu, 23 Mar 2017 14:29:46 -0700 Subject: [PATCH 14/20] gettin that fetch done --- postalicious/public/methods.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/postalicious/public/methods.js b/postalicious/public/methods.js index c6faf78..32889c3 100644 --- a/postalicious/public/methods.js +++ b/postalicious/public/methods.js @@ -18,7 +18,7 @@ function construct(event) { // headers.append(keyHeader1, valueHeader1) console.log('keyheader', valueHeader1, keyHeader1); headers.append(keyHeader1, valueHeader1) - console.log(headers.get('content-type'), '=======', headers.headers); + console.log(headers.get('Accept'), '=======', headers.headers); event.preventDefault() let url = '' url = host + '?' @@ -29,6 +29,12 @@ function construct(event) { } url = url.substring(0, url.length - 1) console.log('url=====', url) + + fetch(url, headers) + .then(function(response){ + console.log('made it',response) + }) + document.getElementById("request_content").innerText = method + ' ' + protocol document.getElementById("request_content2").innerText = url // document.getElementById("request_content3").innerText = headersArray From cd36d84dd32e134d3a749f63e890b2f8385f9b1a Mon Sep 17 00:00:00 2001 From: lizzkats Date: Thu, 23 Mar 2017 17:19:01 -0700 Subject: [PATCH 15/20] getting a response back and adding default input values --- package.json | 1 + postalicious/public/index.html | 21 +++++++------ postalicious/public/methods.js | 53 ++++++++++++++++++++++----------- sandbox-server/index.js | 7 +++++ sandbox-server/routes/trails.js | 1 + 5 files changed, 57 insertions(+), 26 deletions(-) diff --git a/package.json b/package.json index 00c7205..608a8f0 100644 --- a/package.json +++ b/package.json @@ -27,6 +27,7 @@ "devDependencies": { "chai": "^3.5.0", "chai-http": "^3.0.0", + "cors": "^2.8.1", "mocha": "^3.2.0", "pg-promise": "^5.6.4" } diff --git a/postalicious/public/index.html b/postalicious/public/index.html index 3ba218c..c22ea8e 100644 --- a/postalicious/public/index.html +++ b/postalicious/public/index.html @@ -20,8 +20,8 @@
- Host - + Host +
@@ -43,14 +43,14 @@ Headers
- - - + + +
- - - + + +
@@ -81,7 +81,10 @@
-
RESPONSE
+
+ RESPONSE +
+
diff --git a/postalicious/public/methods.js b/postalicious/public/methods.js index 32889c3..a7c05b0 100644 --- a/postalicious/public/methods.js +++ b/postalicious/public/methods.js @@ -2,37 +2,56 @@ //use new header //search fetch //construct url + const protocol = 'http/1.1' const method = document.getElementsByClassName("method-input")[0].value const docKeyLength = document.getElementsByClassName("key").length const docValLength = document.getElementsByClassName("value").length -const headerOptions = document.getElementsByClassName('daheaders') -const headerValue = document.getElementsByClassName('select') +// const headerOptions = document.getElementsByClassName('daheaders') +// const headerValue = document.getElementsByClassName('select') + -const headers = new Headers() function construct(event) { const host = document.getElementsByClassName("host-input")[0].value const keyHeader1 = document.getElementById('header-key1').value const valueHeader1 = document.getElementById('header-value1').value - // headers.append(keyHeader1, valueHeader1) - console.log('keyheader', valueHeader1, keyHeader1); - headers.append(keyHeader1, valueHeader1) - console.log(headers.get('Accept'), '=======', headers.headers); + const keyHeader2 = document.getElementById('header-key2').value + const valueHeader2 = document.getElementById('header-value2').value + const keyHeader3 = document.getElementById('header-key3').value + const valueHeader3 = document.getElementById('header-value3').value + let init = {} + if(keyHeader1.length === 0){ + // console.log('===================',keyHeader1.length); + init[keyHeader1] = valueHeader1 + } + if(keyHeader2.length === 0){ + init[keyHeader2] = valueHeader2 + } + if(keyHeader3.length === 0){ + init[keyHeader3] = valueHeader3 + } + console.log('headers',init, docKeyLength); + const hs = new Headers(init) + event.preventDefault() let url = '' - url = host + '?' - for (var i = 0; i < docKeyLength - 1; i++) { - if(document.getElementsByClassName("key")[i].value.length !== 0){ - url += document.getElementsByClassName("key")[i].value + '=' + document.getElementsByClassName("value")[i].value + '&' + url += host + if(document.getElementsByClassName("key")[0].value.length !== 0){ + url +='?' + for (var i = 0; i < docKeyLength - 1; i++) { + if(document.getElementsByClassName("key")[i].value.length !== 0){ + url += document.getElementsByClassName("key")[i].value + '=' + document.getElementsByClassName("value")[i].value + '&' + //TODO: add uri encoding here ^ + } } + url = url.substring(0, url.length - 1) } - url = url.substring(0, url.length - 1) - console.log('url=====', url) - - fetch(url, headers) - .then(function(response){ - console.log('made it',response) + let myRequest = new Request(url, hs) + fetch(myRequest) + .then((response) => { + console.dir(response) + document.getElementById("response-space").innerText = response }) document.getElementById("request_content").innerText = method + ' ' + protocol diff --git a/sandbox-server/index.js b/sandbox-server/index.js index 0a9993d..7008f3d 100644 --- a/sandbox-server/index.js +++ b/sandbox-server/index.js @@ -1,5 +1,6 @@ const express = require('express') const server = express() +const cors = require('cors') const http = require('http').createServer(server) const path = require('path') const port = process.env.PORT || 3000 @@ -8,6 +9,12 @@ const logger = require('morgan') server.use(logger("combined")) server.use(express.static(path.join(__dirname, 'public'))) +server.use(function(req, res, next) { + res.header("Access-Control-Allow-Origin", "*"); + res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept"); + next(); +}) + server.get('/', function(request, response){ response.send('Welcome to the sandbox!') }) diff --git a/sandbox-server/routes/trails.js b/sandbox-server/routes/trails.js index 23d8d4a..87222b1 100644 --- a/sandbox-server/routes/trails.js +++ b/sandbox-server/routes/trails.js @@ -2,6 +2,7 @@ const express = require('express') const router = express.Router() router.get('/', (request, response) => { + console.log('request', request); response.set('content-type', 'text/plain') .send('Welcome to Sandbox!') }) From 5ff58415965d8fca5c87a29c685fa1d6b801e7ea Mon Sep 17 00:00:00 2001 From: Abraham Ferguson Date: Fri, 24 Mar 2017 16:06:24 -0700 Subject: [PATCH 16/20] completed parsing of http response from sandbox server --- postalicious/public/index.html | 119 +++++++++++----------- postalicious/public/methods.js | 95 ++++++++++++++--- postalicious/public/stylesheets/style.css | 8 +- sandbox-server/index.js | 9 +- sandbox-server/routes/trails.js | 2 +- 5 files changed, 157 insertions(+), 76 deletions(-) diff --git a/postalicious/public/index.html b/postalicious/public/index.html index c22ea8e..b55e058 100644 --- a/postalicious/public/index.html +++ b/postalicious/public/index.html @@ -5,91 +5,96 @@ Postalicious + -
-
-
Postalicious
-
-
-
- Method - -
-
- Host - -
-
-
- Query Parameters -
-
- - - +
+
+
Postalicious
+
+
+
+ Method +
-
- - - +
+ Host +
-
-
- Headers -
-
- - - +
+ Query Parameters +
+
+ + + +
+
+ + + +
-
- - - +
+
+ Headers +
+
+ + + +
+
+ + + +
-
-
+
Body - +
-
+
- +
-
- +
+
-
-
- REQUEST -
-
-
+
+
+ REQUEST +
+
+
+
+
+
-
-
+
+
RESPONSE -
+
+
- +
diff --git a/postalicious/public/methods.js b/postalicious/public/methods.js index a7c05b0..62f353f 100644 --- a/postalicious/public/methods.js +++ b/postalicious/public/methods.js @@ -1,8 +1,3 @@ -//search uriencoded -//use new header -//search fetch -//construct url - const protocol = 'http/1.1' const method = document.getElementsByClassName("method-input")[0].value const docKeyLength = document.getElementsByClassName("key").length @@ -10,8 +5,6 @@ const docValLength = document.getElementsByClassName("value").length // const headerOptions = document.getElementsByClassName('daheaders') // const headerValue = document.getElementsByClassName('select') - - function construct(event) { const host = document.getElementsByClassName("host-input")[0].value const keyHeader1 = document.getElementById('header-key1').value @@ -20,9 +13,13 @@ function construct(event) { const valueHeader2 = document.getElementById('header-value2').value const keyHeader3 = document.getElementById('header-key3').value const valueHeader3 = document.getElementById('header-value3').value + const bodyBox = document.getElementById('request_body').value + let responseHeaders = [] + let responseHeaderValues = [] + let headersAndValues = [] + let status, statusText let init = {} if(keyHeader1.length === 0){ - // console.log('===================',keyHeader1.length); init[keyHeader1] = valueHeader1 } if(keyHeader2.length === 0){ @@ -32,7 +29,7 @@ function construct(event) { init[keyHeader3] = valueHeader3 } console.log('headers',init, docKeyLength); - const hs = new Headers(init) + // const hs = new Headers(init) event.preventDefault() let url = '' @@ -47,11 +44,83 @@ function construct(event) { } url = url.substring(0, url.length - 1) } - let myRequest = new Request(url, hs) + let myRequest = new Request(url) + myRequest.body = bodyBox + // console.log('myRequest====......-----', myRequest); + + function groupChunks(readableStream){ + console.log('hererererere',readableStream); + const lexicon = readableStream.getReader() + const basket = [] + + return grouper() + + function grouper(){ + return lexicon.read().then(({value, done}) => { + // console.log('basket==========', basket); + if(done){ + return basket + } + basket.push(value) + return grouper() + }) + } + } + + // fetch(myRequest) + // .then(response => { + // //let hi = groupChunks(response.body) + // console.log('response::', response) + // response.json().then(result => console.log('RESULT::', result)) + // //console.log('!!!!!!!!!',groupChunks(result)) + // for (let i = 0; i < response.headers.keys.length; i++) { + // responseHeaders.push(response.headers.keys[i]) + // } + // for (let i = 0; i < response.headers.values.length; i++) { + // responseHeaderValues.push(response.headers.values[i]) + // } + // status = response.status + // statusText = response.statusText + // //console.log('===========result', typeof(hi), hi); + // let responseBody // = new TextDecoder("utf-8").decode(hi) + // return 'responseBody' + // }).then(body => { + // console.log('body-----------++', body); + // let contentLength = body.length + // responseHeaders.forEach((header, index) => { + // headersAndValues.push(header) + // headersAndValues.push(': ') + // headersAndValues.push(responseHeaderValues[index]) + // headersAndValues.push('\n') + // }) + // console.log('header==========-------',headersAndValues); + // document.getElementById("response-space").innerText = headersAndValues + ' ' + status + ' ' + statusText + // }) + fetch(myRequest) - .then((response) => { - console.dir(response) - document.getElementById("response-space").innerText = response + .then(response => { + console.log('response', response); + document.getElementById("response-info1").innerText = 'status: ' + response.status + '\n' +'statusText: ' + response.statusText + return response.blob() + }).then(result => { + var reader = new FileReader(); + console.log('blob:', result); + reader.addEventListener("loadend", function() { + // reader.result contains the contents of blob as a typed array + console.log('reader.result::', reader.result); + if(result.type === 'application/json') { + + } + if(result.type === 'text/plain'){ + let output = '' + output += reader.result + '\n' + output += 'content-type: ' + result.type + '\n' + output += 'content-length: ' + result.size + '\n' + document.getElementById("response-info2").innerText = output + } + // document.getElementById("response-space").innerText = + }); + reader.readAsText(result); }) document.getElementById("request_content").innerText = method + ' ' + protocol diff --git a/postalicious/public/stylesheets/style.css b/postalicious/public/stylesheets/style.css index 42895b0..7681c09 100644 --- a/postalicious/public/stylesheets/style.css +++ b/postalicious/public/stylesheets/style.css @@ -1,6 +1,7 @@ .title { background-color: grey; + width: 1267px; } .method-input, .host-input { @@ -24,8 +25,11 @@ height: 100px; width: 200px; } - -.request-body-box, .response-body-box { +.response-body-box { + width: 50%; + height: 250px; +} +.request-body-box{ width: 500px; height: 250px; } diff --git a/sandbox-server/index.js b/sandbox-server/index.js index 7008f3d..d2483e1 100644 --- a/sandbox-server/index.js +++ b/sandbox-server/index.js @@ -5,19 +5,22 @@ const http = require('http').createServer(server) const path = require('path') const port = process.env.PORT || 3000 const logger = require('morgan') +const trails = require('./routes/trails') server.use(logger("combined")) server.use(express.static(path.join(__dirname, 'public'))) + server.use(function(req, res, next) { res.header("Access-Control-Allow-Origin", "*"); res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept"); next(); }) +server.use('/', trails) -server.get('/', function(request, response){ - response.send('Welcome to the sandbox!') -}) +// server.get('/', function(request, response){ +// response.send('Welcome to the sandbox!') +// }) server.set(port) diff --git a/sandbox-server/routes/trails.js b/sandbox-server/routes/trails.js index 87222b1..4cea192 100644 --- a/sandbox-server/routes/trails.js +++ b/sandbox-server/routes/trails.js @@ -2,7 +2,7 @@ const express = require('express') const router = express.Router() router.get('/', (request, response) => { - console.log('request', request); + console.log('request', request.headers); response.set('content-type', 'text/plain') .send('Welcome to Sandbox!') }) From f7c406a5a18883ba9b06516e73f9020a27b59ef3 Mon Sep 17 00:00:00 2001 From: lizzkats Date: Fri, 24 Mar 2017 16:55:00 -0700 Subject: [PATCH 17/20] fixes UI and spacing --- postalicious/public/index.html | 54 +++++++++++------------ postalicious/public/stylesheets/style.css | 8 ++-- 2 files changed, 32 insertions(+), 30 deletions(-) diff --git a/postalicious/public/index.html b/postalicious/public/index.html index b55e058..b3fbced 100644 --- a/postalicious/public/index.html +++ b/postalicious/public/index.html @@ -11,7 +11,7 @@
Postalicious
-
+
Method @@ -29,42 +29,43 @@ Query Parameters
- - - + + +
- - - + + +
Headers -
+
- - - + + +
- - - + + +
-
- Body - + Body + +
+
-
+
-
+
@@ -73,28 +74,27 @@
-
-
+
+
REQUEST -
+
+
-
-
-
+
+
RESPONSE
-
- + diff --git a/postalicious/public/stylesheets/style.css b/postalicious/public/stylesheets/style.css index 7681c09..4badded 100644 --- a/postalicious/public/stylesheets/style.css +++ b/postalicious/public/stylesheets/style.css @@ -25,11 +25,13 @@ height: 100px; width: 200px; } + .response-body-box { width: 50%; - height: 250px; + height: 350px; } -.request-body-box{ + +.request-body-box { width: 500px; - height: 250px; + height: 350px; } From a88520bebe554b4701f18b18b38a17add2d53721 Mon Sep 17 00:00:00 2001 From: Abraham Ferguson Date: Fri, 24 Mar 2017 16:55:26 -0700 Subject: [PATCH 18/20] cleaned up console logs and commented code --- postalicious/public/index.html | 2 +- postalicious/public/methods.js | 109 +++++++++++--------------- postalicious/test/post_tests.js | 0 sandbox-server/api-methods/methods.js | 11 --- 4 files changed, 45 insertions(+), 77 deletions(-) delete mode 100644 postalicious/test/post_tests.js delete mode 100644 sandbox-server/api-methods/methods.js diff --git a/postalicious/public/index.html b/postalicious/public/index.html index b55e058..7abe8dc 100644 --- a/postalicious/public/index.html +++ b/postalicious/public/index.html @@ -69,7 +69,7 @@
- +
diff --git a/postalicious/public/methods.js b/postalicious/public/methods.js index 62f353f..5d81cc1 100644 --- a/postalicious/public/methods.js +++ b/postalicious/public/methods.js @@ -2,10 +2,9 @@ const protocol = 'http/1.1' const method = document.getElementsByClassName("method-input")[0].value const docKeyLength = document.getElementsByClassName("key").length const docValLength = document.getElementsByClassName("value").length -// const headerOptions = document.getElementsByClassName('daheaders') -// const headerValue = document.getElementsByClassName('select') function construct(event) { + event.preventDefault() const host = document.getElementsByClassName("host-input")[0].value const keyHeader1 = document.getElementById('header-key1').value const valueHeader1 = document.getElementById('header-value1').value @@ -19,6 +18,7 @@ function construct(event) { let headersAndValues = [] let status, statusText let init = {} + if(keyHeader1.length === 0){ init[keyHeader1] = valueHeader1 } @@ -28,88 +28,31 @@ function construct(event) { if(keyHeader3.length === 0){ init[keyHeader3] = valueHeader3 } - console.log('headers',init, docKeyLength); - // const hs = new Headers(init) - event.preventDefault() let url = '' url += host if(document.getElementsByClassName("key")[0].value.length !== 0){ url +='?' for (var i = 0; i < docKeyLength - 1; i++) { if(document.getElementsByClassName("key")[i].value.length !== 0){ - url += document.getElementsByClassName("key")[i].value + '=' + document.getElementsByClassName("value")[i].value + '&' - //TODO: add uri encoding here ^ + url += uriEncondingComponent(document.getElementsByClassName("key")[i].value) + '=' + uriEncondingComponent(document.getElementsByClassName("value")[i].value + '&') } } url = url.substring(0, url.length - 1) } + let myRequest = new Request(url) myRequest.body = bodyBox - // console.log('myRequest====......-----', myRequest); - - function groupChunks(readableStream){ - console.log('hererererere',readableStream); - const lexicon = readableStream.getReader() - const basket = [] - - return grouper() - - function grouper(){ - return lexicon.read().then(({value, done}) => { - // console.log('basket==========', basket); - if(done){ - return basket - } - basket.push(value) - return grouper() - }) - } - } - - // fetch(myRequest) - // .then(response => { - // //let hi = groupChunks(response.body) - // console.log('response::', response) - // response.json().then(result => console.log('RESULT::', result)) - // //console.log('!!!!!!!!!',groupChunks(result)) - // for (let i = 0; i < response.headers.keys.length; i++) { - // responseHeaders.push(response.headers.keys[i]) - // } - // for (let i = 0; i < response.headers.values.length; i++) { - // responseHeaderValues.push(response.headers.values[i]) - // } - // status = response.status - // statusText = response.statusText - // //console.log('===========result', typeof(hi), hi); - // let responseBody // = new TextDecoder("utf-8").decode(hi) - // return 'responseBody' - // }).then(body => { - // console.log('body-----------++', body); - // let contentLength = body.length - // responseHeaders.forEach((header, index) => { - // headersAndValues.push(header) - // headersAndValues.push(': ') - // headersAndValues.push(responseHeaderValues[index]) - // headersAndValues.push('\n') - // }) - // console.log('header==========-------',headersAndValues); - // document.getElementById("response-space").innerText = headersAndValues + ' ' + status + ' ' + statusText - // }) fetch(myRequest) .then(response => { - console.log('response', response); document.getElementById("response-info1").innerText = 'status: ' + response.status + '\n' +'statusText: ' + response.statusText return response.blob() }).then(result => { var reader = new FileReader(); - console.log('blob:', result); reader.addEventListener("loadend", function() { - // reader.result contains the contents of blob as a typed array - console.log('reader.result::', reader.result); if(result.type === 'application/json') { - + //TODO: } if(result.type === 'text/plain'){ let output = '' @@ -118,12 +61,48 @@ function construct(event) { output += 'content-length: ' + result.size + '\n' document.getElementById("response-info2").innerText = output } - // document.getElementById("response-space").innerText = - }); + }) reader.readAsText(result); }) document.getElementById("request_content").innerText = method + ' ' + protocol document.getElementById("request_content2").innerText = url - // document.getElementById("request_content3").innerText = headersArray +} +function build(event) { + event.preventDefault() + const host = document.getElementsByClassName("host-input")[0].value + const keyHeader1 = document.getElementById('header-key1').value + const valueHeader1 = document.getElementById('header-value1').value + const keyHeader2 = document.getElementById('header-key2').value + const valueHeader2 = document.getElementById('header-value2').value + const keyHeader3 = document.getElementById('header-key3').value + const valueHeader3 = document.getElementById('header-value3').value + const bodyBox = document.getElementById('request_body').value + + let init = {} + + if(keyHeader1.length === 0){ + init[keyHeader1] = valueHeader1 + } + if(keyHeader2.length === 0){ + init[keyHeader2] = valueHeader2 + } + if(keyHeader3.length === 0){ + init[keyHeader3] = valueHeader3 + } + + let url = '' + url += host + if(document.getElementsByClassName("key")[0].value.length !== 0){ + url +='?' + for (var i = 0; i < docKeyLength - 1; i++) { + if(document.getElementsByClassName("key")[i].value.length !== 0){ + url += uriEncondingComponent(document.getElementsByClassName("key")[i].value) + '=' + uriEncondingComponent(document.getElementsByClassName("value")[i].value + '&') + } + } + url = url.substring(0, url.length - 1) + } + + document.getElementById("request_content").innerText = method + ' ' + protocol + document.getElementById("request_content2").innerText = url } diff --git a/postalicious/test/post_tests.js b/postalicious/test/post_tests.js deleted file mode 100644 index e69de29..0000000 diff --git a/sandbox-server/api-methods/methods.js b/sandbox-server/api-methods/methods.js deleted file mode 100644 index 1eb10e9..0000000 --- a/sandbox-server/api-methods/methods.js +++ /dev/null @@ -1,11 +0,0 @@ -const pgp = require('pg-promise') -const db = pgp('sandBox') - -const arr = ['doodads'] - -const finder = (str) => { - console.log('herere') - console.log(str) -} - -module.exports = { finder } From 1b776444fa3811daa1d71104ac0adacae58ba9e5 Mon Sep 17 00:00:00 2001 From: Lizz Katsnelson Date: Fri, 24 Mar 2017 17:30:55 -0700 Subject: [PATCH 19/20] Update README.md --- README.md | 106 +++++++++++++++++++++++++++--------------------------- 1 file changed, 53 insertions(+), 53 deletions(-) diff --git a/README.md b/README.md index b48d979..f7422b6 100644 --- a/README.md +++ b/README.md @@ -10,63 +10,63 @@ See http://jsdev.learnersguild.org/goals/194-Postalicious-Demystifying_HTTP.html ## Sandbox Server -- [ ] Can run the command npm run sandbox-server (or npm run sb, if you want to save some typing) to start the sandbox web server at port 3000. -- [ ] The sandbox server source code is written using the Express library. -- [ ] Sending a GET request to the path / responds with - - [ ] a 200 (OK) status code a plain-text response - - [ ] body with the content Welcome to Sandbox! - - [ ] the Content-Type header set to text/plain -- [ ] Sending a GET request to the path /search?q=doodads responds with - - [ ] a 200 (OK) status code - - [ ] a plain-text response body with the content You searched for: "doodads" (it doesn’t need to actually do any searching, just return the plain text) - - [ ] the Content-Type header set to text/plain -- [ ] Sending a GET request to the path /search responds with… - - [ ] a 400 (Bad Request) status code - - [ ] a plain-text response body with the content You didn't provide a search query term :( - - [ ] the Content-Type header set to text/plain -- [ ] Sending a POST request to the path /things with a plain text body flying car responds with… - - [ ] a 201 (Created) status code - - [ ] a plain-text response body with the content New thing created: "flying car"! (it doesn’t need to actually create anything, just return the plain text) - - [ ] the Content-Type header set to text/plain -- [ ] Sending a GET request to the path /somefile with an Accept header of text/plain responds with… - - [ ] a 200 (OK) status code - - [ ] a plain-text response body with the content This is a plain text file - - [ ] the Content-Type header set to text/plain -- [ ] Sending a GET request to the path /somefile with an Accept header of text/html responds with… - - [ ] a 200 (OK) status code - - [ ] an HTML response body with the content This is an HTML file - - [ ] the Content-Type header set to text/html -- [ ] Sending a GET request to the path /myjsondata with an Accept header of application/json responds with… - - [ ] a 200 (OK) status code - - [ ] an HTML response body with the content { "title": "some JSON data" } - - [ ] the Content-Type header set to application/json -- [ ] Sending a GET request to the path /old-page responds with… - - [ ] a 301 (Moved Permanently) status code - - [ ] the Location header set to http://localhost:3000/newpage -- [ ] Sending a POST request to the path /admin-only responds with a 403 (Forbidden) status code -- [ ] Sending a GET request to the path /not-a-page responds with a 404 (Not Found) status code -- [ ] Sending a GET request to the path /server-error responds with a 500 (Internal Server Error) staus code +- [x] Can run the command npm run sandbox-server (or npm run sb, if you want to save some typing) to start the sandbox web server at port 3000. +- [x] The sandbox server source code is written using the Express library. +- [x] Sending a GET request to the path / responds with + - [x] a 200 (OK) status code a plain-text response + - [x] body with the content Welcome to Sandbox! + - [x] the Content-Type header set to text/plain +- [x] Sending a GET request to the path /search?q=doodads responds with + - [x] a 200 (OK) status code + - [x] a plain-text response body with the content You searched for: "doodads" (it doesn’t need to actually do any searching, just return the plain text) + - [x] the Content-Type header set to text/plain +- [x] Sending a GET request to the path /search responds with… + - [x] a 400 (Bad Request) status code + - [x] a plain-text response body with the content You didn't provide a search query term :( + - [x] the Content-Type header set to text/plain +- [x] Sending a POST request to the path /things with a plain text body flying car responds with… + - [x] a 201 (Created) status code + - [x] a plain-text response body with the content New thing created: "flying car"! (it doesn’t need to actually create anything, just return the plain text) + - [x] the Content-Type header set to text/plain +- [x] Sending a GET request to the path /somefile with an Accept header of text/plain responds with… + - [x] a 200 (OK) status code + - [x] a plain-text response body with the content This is a plain text file + - [x] the Content-Type header set to text/plain +- [x] Sending a GET request to the path /somefile with an Accept header of text/html responds with… + - [x] a 200 (OK) status code + - [x] an HTML response body with the content This is an HTML file + - [x] the Content-Type header set to text/html +- [x] Sending a GET request to the path /myjsondata with an Accept header of application/json responds with… + - [x] a 200 (OK) status code + - [x] an HTML response body with the content { "title": "some JSON data" } + - [x] the Content-Type header set to application/json +- [x] Sending a GET request to the path /old-page responds with… + - [x] a 301 (Moved Permanently) status code + - [x] the Location header set to http://localhost:3000/newpage +- [x] Sending a POST request to the path /admin-only responds with a 403 (Forbidden) status code +- [x] Sending a GET request to the path /not-a-page responds with a 404 (Not Found) status code +- [x] Sending a GET request to the path /server-error responds with a 500 (Internal Server Error) staus code ##Postalicious -- [ ] Can run the command npm run postalicious (or npm run pl, if you want to save some typing) to start the Postalicious app at port 3001. -- [ ] Users can visit the main page of the Postalicious site at http://localhost:3001. -- [ ] Main page has three main sections: - - [ ] Request builder HTML form - - [ ] Raw HTTP request - - [ ] Raw HTTP response -- [ ] When a user fills out the HTML form and clicks a “Send” button… - - [ ] The raw HTTP request is generated and shown - - [ ] The HTTP request is sent, and the raw response message is shown - - [ ] Users can fill out an HTML form to specify HTTP request details. -- [ ] Submitting the form will send the request according to the specified details. -- [ ] Using the HTML form, users can specify… - - [ ] host and path - - [ ] HTTP verb/method - - [ ] query parameter keys + values - - [ ] header keys + values - - [ ] request body +- [x] Can run the command npm run postalicious (or npm run pl, if you want to save some typing) to start the Postalicious app at port 3001. +- [x] Users can visit the main page of the Postalicious site at http://localhost:3001. +- [x] Main page has three main sections: + - [x] Request builder HTML form + - [x] Raw HTTP request + - [x] Raw HTTP response +- [x] When a user fills out the HTML form and clicks a “Send” button… + - [x] The raw HTTP request is generated and shown + - [x] The HTTP request is sent, and the raw response message is shown + - [x] Users can fill out an HTML form to specify HTTP request details. +- [x] Submitting the form will send the request according to the specified details. +- [x] Using the HTML form, users can specify… + - [x] host and path + - [x] HTTP verb/method + - [x] query parameter keys + values + - [x] header keys + values + - [x] request body ##Stretch From e282559b421972d13dd86d9d022b7341b445cc74 Mon Sep 17 00:00:00 2001 From: Lizz Katsnelson Date: Sun, 26 Mar 2017 15:45:09 -0700 Subject: [PATCH 20/20] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index f7422b6..f6aedc0 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ # Postalicious -A clone of the Postman chrome extension. +A clone of the Postman app. ## Description See http://jsdev.learnersguild.org/goals/194-Postalicious-Demystifying_HTTP.html for description.