davetemplin / web-request Goto Github PK
View Code? Open in Web Editor NEWSimplifies making web requests with TypeScript async/await
License: MIT License
Simplifies making web requests with TypeScript async/await
License: MIT License
I'm downloading some information from a website. I can't find which response set the cookies. But I know their value. How can I set those cookies in my script?
Typescript version: 1.8.10 (should be the same for typescript < 2)
Web-request version with compile errors: 1.0.7
Last working web-request version: 1.0.6
Errors:
./node_modules/web-request/index.d.ts
Error:(150, 25) TS1110:Type expected.
Error:(150, 25) TS7008:Member 'null' implicitly has an 'any' type.
Error:(177, 5) TS2300:Duplicate identifier 'readonly'.
Error:(177, 14) TS1005:'=' expected.
random.ts
Error:(43, 38) TS2339:Property 'content' does not exist on type 'Response<string>'.
1.0.6 and 1.0.7 have different index.d.ts file
Additional info: error on typescript 1.8.10 from node_modules
, system version of typescript - 2.0.3
Would it be at all possible to have a es5 redist so as to be friendly with projects like create react app?
I want to pass 2 headers so I tried:
const deployRequest = await WebRequest.stream('https://myurl',
{
method: 'post',
headers: [
{'Content-Type': 'application/zip'},
{'Authorization': `Bearer ${apiKey}`}
]
});
fs.createReadStream(zippedSite).pipe(deployRequest);
const deployResponse = await deployRequest.response;
i'm not sure i'm using the correct format for request headers since i get: 401 Unauthorized
and if i use the same headers with curl
all is ok.. anything i'm doing wrong?
Hi,
in the request implementation, cqlling request.default returns you a wrapper that you'll use to issue your next requests using those defaults.
In web-request, calling default only calls request.default and returns void.
For --strictNullChecks
if you need binary content.
Look at #8 for more details.
Hi,
I am struggeling with using web-request and cookies. It surely is simple to have web-request activate and return cookies, but I can't seem to get it to use/send the cookie on the follow-up request. Simply sending another request via web-request does not seem to work (no cookie at the server side). The "best" I could get is an error 400 with "Invalid cookie handler" when I try sending the received cookie as header with the next request.
In exploring using cookies I also wondered, if there is a way to access the request.jar() method via web-request to create a new jar for cookies, as mentioned in the description of the request module. Or do I have to implement my own jar on CookieJar?
Thanks for any advice,
Stefan
I know is not the best idea to add a body to a delete request, but sometimes some APIs require to get some more info attached (this is my particular case right now).
Could you please add the possibility of having the body sent through web-request?
There is a discussion in StackOverflow on the subject that you might find interesting.
http://stackoverflow.com/questions/299628/is-an-entity-body-allowed-for-an-http-delete-request
I keep getting this error when compiling my Angular 2 project:
ERROR in /Users/user/workspace/app/client/node_modules/web-request/index.d.ts (1,23): Cannot find module 'http'.
ERROR in /Users/user/workspace/app/client/node_modules/web-request/index.d.ts (2,26): Cannot find module 'stream'.
ERROR in /Users/user/workspace/app/client/node_modules/web-request/index.d.ts (103,40): Cannot find name 'Buffer'.
ERROR in /Users/user/workspace/app/client/node_modules/web-request/index.d.ts (105,82): Cannot find name 'Buffer'.
ERROR in /Users/user/workspace/app/client/node_modules/web-request/index.d.ts (106,19): Cannot find name 'Buffer'.
ERROR in /Users/user/workspace/app/client/node_modules/web-request/index.d.ts (111,16): Cannot find name 'Buffer'.
ERROR in /Users/user/workspace/app/client/node_modules/web-request/index.d.ts (158,11): Cannot find name 'Buffer'.
ERROR in /Users/user/workspace/app/client/node_modules/web-request/index.d.ts (159,12): Cannot find name 'Buffer'.
ERROR in /Users/user/workspace/app/client/node_modules/web-request/index.d.ts (161,10): Cannot find name 'Buffer'.
I get this after running:
npm install --save web-request
npm install @types/node
When I view the code in web-request/index.d.ts in my code editor there is no error; it just shows up in compilation.
Node version: v6.11.3
Hello, I was curious about how you would recommend handling errors using this package that come from the timeout being reached?
Thank you!
node -v v6.10.1
@angular/cli: 1.4.3
node: 6.10.1
os: win32 x64
@angular/animations: 4.4.6
@angular/common: 4.4.6
@angular/compiler: 4.4.6
@angular/core: 4.4.6
@angular/forms: 4.4.6
@angular/http: 4.4.6
@angular/platform-browser: 4.4.6
@angular/platform-browser-dynamic: 4.4.6
@angular/router: 4.4.6
@angular/cli: 1.4.3
@angular/compiler-cli: 4.4.6
@angular/language-service: 4.4.6
typescript: 2.3.4
Any suggestions? is this library good for typescript angular work?
WebRequest.defaults({ headers: {'User-Agent': 'curl/7.28.1'} });
var data = await WebRequest.get('http://localhost');
The request made over the wire:
GET / HTTP/1.1
host: localhost
Connection: close
What am i doing wrong? User-Agent
doesn't make it in..
Using web-request 1.0.7
from npm.
The title is self-explanatory. I don't know where the documentation is or where to get it or if there even is one.
https://github.com/request/request#debugging
Would be nice to be able to do WebRequest.defaults({debug: true});
import * as WebRequest from 'web-request';
(async function () {
var data = {
"id": 5,
"title": "json-server5",
"author": "typicode5"
};
await WebRequest.post('http://192.168.22.10:3000/posts', {headers: {'Content-Type': 'application/json'}}, data);
})();
I try to use WebRequest post JSON data with above code.
but always get fatal error:
(node:45899) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 2): Error: Argument error, options.body.
_http_outgoing.js:456
throw new TypeError('First argument must be a string or Buffer');
^
TypeError: First argument must be a string or Buffer
at ClientRequest.OutgoingMessage.write (_http_outgoing.js:456:11)
at Request.write (/Users/martinsun/node_modules/request/request.js:1514:27)
at end (/Users/martinsun/node_modules/request/request.js:552:18)
at Immediate. (/Users/martinsun/node_modules/request/request.js:581:7)
at runCallback (timers.js:637:20)
at tryOnImmediate (timers.js:610:5)
at processImmediate [as _immediateCallback] (timers.js:582:5)
Would you please let me know how to fix the problem?
Running
ng serve --prod -sm
with my Angular 2 app produces the following error:
ERROR in vendor.6cd5e9b8eaa69eb62924.bundle.js from UglifyJs
Unexpected token operator «*», expected punc «(» [/Users/user/workspace/app/client/node_modules/web-request/index.js:13,0][vendor.6cd5e9b8eaa69eb62924.bundle.js:60875,51]
which means that UglifyJS is reaching web-request's function*
syntax and freaking out. Compilation works perfectly fine on development (I assume because UglifyJS isn't being run), but I cannot get my production build to work unless I use something other than web-request.
Hi, I have been using your wonderful module recently and I noticed that if i try and use the delete functionality as a named import it wont compile as delete is a reserved word in javascript. For example
import {json, delete} from 'web-request';
The above throws an error because of the name "delete". Is it possible to rename this to something that is not a reserved word?
I should note that the below works, however I really like having named imports, I feel its a lot cleaner
import WebRequest from 'web-request';
WebRequest.delete('http://bla.com/bla');
Hi,
Sorry, the issue is not the best format to ask that but I didn't thought of a better way.
Did you plan to release a new version with the already integrated modifications in master?
I have some dependencies on it so I built it myself but I need to work with someone else on the project, so it'll be simpler to release it to everyone ^^.
thanks!
IDEA is pointing out that you have:
import * as stream from 'stream';
export declare function stream(uri: string, options?: RequestOptions, content?: any): Request<void>;
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.