[Node.js]27. Level 5: URL Building & Doing the Request
2023-09-14 08:59:21 时间
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. } });
相关文章
- From Docker to Kubernetes(三)- Docker Volume&Compose
- 参会指南丨第二届SmartNIC & DPU技术创新峰会
- webpack系列---webpack介绍&基本使用
- 内功修炼之lodash—— clone&cloneDeep(一定有你遗漏的js基础知识)
- 第2章 WEB02-CSS&JS篇-视频教程-第一部分
- 云原生虚拟网络 tun/tap & veth-pair
- JS模块化—CJS&AMD&CMD&ES6-前端面试知识点查漏补缺
- JS面试题-js新增基本数据类型BigInt
- Js生成二维码_js在线生成二维码
- Vue.js – 引入外部 JS 文件
- ECCV&CVPR论文速递2022.7.5!最新成果demo展示
- NeurIPS 2022 Oral | 离线强化学习新范式!京东科技&清华提出解耦式学习算法
- ATT&CK实战系列-红队实战(二)
- 原生 JS 实现 HTML 转 Markdown ,html2md.js
- 原生 JS 实现 HTML 转 Markdown,以及其实现逻辑(html2md.js 或 html2markdown.js)
- 使用Node.js连接MySQL数据库(node-mysql)
- 使用Node.js实现对MSSQL数据库的连接(node连接 mssql)
- Node.js和MSSQL数据库的完美结合:使用node mssql模块(node mssql模块)
- 如何增加Oracle数据库的AMP值(amp值oracle)
- php&java(二)
- 用js怎么把&字符换成"&:"
- js对象之JS入门之Array对象操作小结
- js获取坐标通过JS得到当前焦点(鼠标)的坐标属性
- js中传递特殊字符(+,&)的方法