2.2 KiB
2.2 KiB
id, title, challengeType, forumTopicId, localeTitle
id | title | challengeType | forumTopicId | localeTitle |
---|---|---|---|---|
587d7fb2367417b2b2512bf5 | Get Route Parameter Input from the Client | 2 | 301513 | 从客户端获取路由参数输入 |
Description
req.params
对象中找到。
route_path: '/user/:userId/book/:bookId'
actual_request_URL: '/user/546/book/6754'
req.params: {userId: '546', bookId: '6754'}
Instructions
GET /:word/echo
构建一个 echo 服务,响应一个采用{echo: word}
结构的 JSON 对象。你可以在req.params.word
中找到要重复的单词。你可以在浏览器的地址栏测试你的路由,访问一些匹配的路由,比如:your-app-rootpath/freecodecamp/echo
Tests
tests:
- text: 测试 1:你的 echo 服务应该正确地重复单词
testString: 'getUserInput => $.get(getUserInput(''url'') + ''/eChOtEsT/echo'').then(data => { assert.equal(data.echo, ''eChOtEsT'', ''Test 1: the echo server is not working as expected'') }, xhr => { throw new Error(xhr.responseText); })'
- text: 测试 2:你的 echo 服务应该正确地重复单词
testString: 'getUserInput => $.get(getUserInput(''url'') + ''/ech0-t3st/echo'').then(data => { assert.equal(data.echo, ''ech0-t3st'', ''Test 2: the echo server is not working as expected'') }, xhr => { throw new Error(xhr.responseText); })'
Challenge Seed
Solution
/**
Backend challenges don't need solutions,
because they would need to be tested against a full working project.
Please check our contributing guidelines to learn more.
*/