Skip to content
Permalink
Browse files
03_10_19
  • Loading branch information
Tiago Ferreira committed Oct 3, 2019
1 parent 616b78e commit ea6d1fecda58f90df69b8ecf32853441847d79b6
Showing 1 changed file with 29 additions and 5 deletions.
@@ -37,19 +37,43 @@ router.get('/anon', ctx => {
// anon case
})

router.get('/books/:index', ctx => {
const books = ['The Hobbit', 'Alice in Wonderland', 'The Secret Garden']
router.get('/books/:index/:index2', ctx => {
const books = ['The Hobbit', 'Alice in Wonderland', 'The Secret Garden', 'The Lord of the Rings']
const parameters = ctx.params
console.log(parameters)
const title = books[parameters.index]
ctx.body = title
const title = books[parameters.index] + ' ' + books[parameters.index2]

if(isNaN(parameters.index) || isNaN(parameters.index2)){

ctx.body = 'Indexes arent numbers';

} else {
if(Number.isInteger(parameters.index) || Number.isInteger(parameters.index2)){

ctx.body = 'Indexes arent integers';

} else {

if(parameters.index <= 3 && parameters.index2 <= 3){

ctx.body = title;
}
}
}
})

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()
if(ctx.query.format === 'lower') myname = myname.toLowerCase()
if(ctx.query.format === 'reverse'){

var words = myname.split(' ');
//console.log(words[1]);
var reversed = words.reverse();
myname = reversed.join(' ');
}
// only applies uppercase if formatting query exists
ctx.body = `hello ${myname}`
})

0 comments on commit ea6d1fe

Please sign in to comment.