Skip to content

Bug fix + Better Readability #1

Closed
wants to merge 2 commits into from
Closed
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
2 changes: 1 addition & 1 deletion 02 HTTP.md
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ Whilst URL parameters are used to define unique URLS to identify online resource
2. Now change the URL to `/hello/John%20Doe?format=upper`.
1. Notice that the same data has been displayed just the format has changed.

Open the `index.js` file. The route is between lines 37-43.
Open the `index.js` file. The route is between lines 43-47.

1. Notice that the query string(s) are not part of the route.
2. The query string comprises name-value pairs.
Expand Down
5 changes: 3 additions & 2 deletions exercises/02_http/01_url/index.js
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
#!/usr/bin/env node

'use strict'

/* IMPORTING MODULES */
const Koa = require('koa')
const Router = require('koa-router')
Expand All @@ -25,9 +23,11 @@ function hello(ctx) {
}

router.get('/', hello)
//base case

router.get('/anon', ctx => {
ctx.body = 'Hello World'
//anon case
})

router.get('/books/:index', ctx => {
Expand All @@ -43,6 +43,7 @@ router.get('/name', ctx => ctx.body = JSON.stringify(ctx.query))
router.get('/hello/:name', ctx => {
let myname = ctx.params.name
if(ctx.query.format === 'upper') myname = myname.toUpperCase()
//only applies uppercase if formatting query exists
ctx.body = `hello ${myname}`
})

Expand Down