Files
freeCodeCamp/curriculum/challenges/chinese/05-apis-and-microservices/basic-node-and-express/get-query-parameter-input-from-the-client.chinese.md
Beau Carnes 6b1992ee7c fix: Add Api challenges - Chinese translation (#35164)
* fix: Add Api challenges - Chinese translation

* fix: md formatting

* fix: md formatting
2019-05-06 06:31:26 -05:00

2.4 KiB
Raw Blame History

id, title, localeTitle, challengeType
id title localeTitle challengeType
587d7fb2367417b2b2512bf6 Get Query Parameter Input from the Client 从客户端获取查询参数输入 2

Description

0从客户端获取输入的另一种常用方法是使用查询字符串对路径路径后的数据进行编码。查询字符串由问号分隔并包括field = value couple。每对夫妇用和号隔开。 Express可以解析查询字符串中的数据并填充对象req.query 。某些字符不能在URL中它们必须以不同的格式编码才能发送它们。如果您使用JavaScript中的API则可以使用特定方法对这些字符进行编码/解码。
route_path: '/library'
actual_request_URL: '/library?userId=546&bookId=6754'
req.query: {userId: '546', bookId: '6754'}
0构建一个以GET /name挂载的API端点。使用结构{ name: 'firstname lastname'}回复JSON文档。名字和姓氏参数应该在查询字符串中编码例如?first=firstname&last=lastname0提示:在下面的练习中,我们将在相同/name路径路径的POST请求中接收数据。如果需要可以使用方法app.route(path).get(handler).post(handler) 。此语法允许您在同一路径路径上链接不同的动词处理程序。您可以节省一些打字,并拥有更清晰的代码。

Instructions

Tests

tests:
  - text: '测试1您的API端点应使用正确的名称进行响应'
    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: '测试2您的APi端点应以正确的名称响应'
    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