[Node.js]27. Level 5: URL Building & Doing the Request
2023-09-14 09:00:56 时间
Let's create a page which calls the twitter search API and displays the last few results for Code School. The first step is to construct the proper URL, which is all you need to do in this challenge.
Complete the URL options which will be sent into the the url
module's format method. The URL you'll want to construct is the following:
http://search.twitter.com/search.json?q=codeschool
var url = require('url'); options = { // add URL options here protocol: "http", host: 'search.twitter.com', pathname: '/search.json', query: {q: "codeschool"} }; var searchURL = url.format(options); console.log(searchURL);
Next we'll need to include the request module, use that to do a simple web request, and print the returned JSON out to the console. You'll want to check out this example in the readme.
var url = require('url'); var request = require('request'); options = { protocol: "http:", host: "search.twitter.com", pathname: '/search.json', query: { q: "codeschool"} }; var searchURL = url.format(options); request(searchURL, function(err, res, body){ if (!err && res.statusCode == 200) { console.log(body) // Print the google web page. } });
相关文章
- js中的bool值转换及"&&" 、"||"、 "!!"详解
- docker for windows & dotnet core app
- js/jquery 实时监听输入框值变化的完美方案:oninput & onpropertychange
- [ES6] Objects create-shorthand && Destructuring
- [Node.js]29. Level 6: Socket.io: Setting up Socket.io server-side & Client socket.io setup
- [Node.js]27. Level 5: URL Building & Doing the Request
- [ReasonML] Named & optional params
- js中的|| 和 &&
- 华为OD机试 - 几何平均值最大子数组(Java & JS & Python)
- 华为OD机试 - 最佳对手(Java & JS & Python)
- 华为OD机试 - 信号发射和接收(Java & JS & Python)
- 华为OD机试 - 组合出合法最小数(Java & JS & Python)
- 华为OD机试 - 最多等和不相交连续子序列(Java & JS & Python)
- 华为OD机试 - 新学校选址(Java & JS & Python)
- 华为OD机试 - 二元组个数(Java & JS & Python)
- 华为OD机试 - 探索地块建立(Java & JS & Python)
- 华为OD机试 - 最大社交距离(Java & JS & Python)
- 华为OD机试 - 篮球比赛(Java & JS & Python)
- 华为OD机试 - 书籍叠放(Java & JS & Python)
- 【nodejs原理&源码赏析(6)】深度剖析cluster模块源码与node.js多进程
- 【编程实践】Raft 算法的原理 & go代码实例
- git 解决冲突之 theirs & ours
- 前端基础 & Bootstrap框架
- cocos2d-x 3.0游戏实例学习笔记《卡牌塔防》第七步---英雄要升级&属性--解析csv配置文件