2.4 KiB
2.4 KiB
id | title | challengeType |
---|---|---|
587d7fb2367417b2b2512bf6 | Get Query Parameter Input from the Client | 2 |
Description
req.query
. Some characters cannot be in URLs, they have to be encoded in a different format before you can send them. If you use the API from JavaScript, you can use specific methods to encode/decode these characters.
route_path: '/library'Build an API endpoint, mounted at
actual_request_URL: '/library?userId=546&bookId=6754'
req.query: {userId: '546', bookId: '6754'}
GET /name
. Respond with a JSON document, taking the structure { name: 'firstname lastname'}
. The first and last name parameters should be encoded in a query string e.g. ?first=firstname&last=lastname
.
TIP: In the following exercise we are going to receive data from a POST request, at the same /name
route path. If you want you can use the method app.route(path).get(handler).post(handler)
. This syntax allows you to chain different verb handlers on the same path route. You can save a bit of typing, and have cleaner code.
Instructions
Tests
- text: 'Test 1 : Your API endpoint should respond with the correct name'
testString: 'getUserInput => $.get(getUserInput(''url'') + ''/name?first=Mick&last=Jagger'').then(data => { assert.equal(data.name, ''Mick Jagger'', ''Test 1: "GET /name" route does not behave as expected'') }, xhr => { throw new Error(xhr.responseText); })'
- text: 'Test 2 : Your APi endpoint should respond with the correct name'
testString: 'getUserInput => $.get(getUserInput(''url'') + ''/name?last=Richards&first=Keith'').then(data => { assert.equal(data.name, ''Keith Richards'', ''Test 2: "GET /name" route does not behave as expected'') }, xhr => { throw new Error(xhr.responseText); })'
Challenge Seed
Solution
// solution required