SuperAgent

Axios vs Superagent

别说谁变了你拦得住时间么 提交于 2019-12-21 01:21:34
问题 If I use Axios and Superagent to make a call to the same api one after another I get Superagent's response first in the console logs in both cases i.e if I call one first than the other and vice versa. Does that mean one is faster than the other or is something else entirely? getUser() { axios.get('/api/getuser') .then((res) => { console.log(err,res) }) .catch((err,res) => { console.log(err,res) }) request .get('api/getuser') .end((err, res) => { console.log(err,res) }); } 回答1: The difference

How can I inject a custom HTTP Header into every request that SuperAgent makes?

▼魔方 西西 提交于 2019-12-20 19:43:54
问题 Clearly SuperAgent supports custom HTTP headers: request .post('/api/pet') .send({ name: 'Manny', species: 'cat' }) .set('X-API-Key', 'foobar') .set('Accept', 'application/json') .end(function(err, res){ if (res.ok) { alert('yay got ' + JSON.stringify(res.body)); } else { alert('Oh no! error ' + res.text); } }); My Question: If I'm pulling down SuperAgent via npm, how can I inject my own HTTP header across all requests that SuperAgent makes? Note: I'm entire willing to create a new npm

Read response output buffer/stream with supertest/superagent on node.js server

廉价感情. 提交于 2019-12-20 11:32:07
问题 I am trying to write a test that checks whether an API route outputs a ZIP file with the correct contents. I am using mocha and supertest for testing, and I would like to actually read the output stream/buffer, read the zip file contents and see if the contents are correct. Any ideas how should I do it? When I try to read res.body , it's just an empty object. request(app) .get( "/api/v1/orders/download?id[]=1&id=2" ) .set( "Authorization", authData ) .expect( 200 ) .expect( 'Content-Type',

Basic authentication : failure supergaent+OSX , success on superagent+Redhat , success on Postman+OSX,

落爺英雄遲暮 提交于 2019-12-20 03:13:31
问题 Using POSTMAN , everything is fine : I pass the same headers,params,... to superagent as following : const superagent = require('superagent'); const grab = require('ps-grab'); superagent.get('https://x.rathath.net/issue_statuses.json') .set({ 'Accept': 'application/json', 'Content-Type': 'application/json' }) .auth(grab('--user'),grab('--password')) .send({}) .end((error,response)=>{ console.log(response.text); }); However it is failed ! I have a doubt in : superagent+Authorization Header+

Mocha tests using superagent + promises timeout rather than fail with 'expect'

允我心安 提交于 2019-12-11 05:52:38
问题 I'm using mocha to run a number of integration tests against an external web service. I use superagent-promise for the request/response handling, and I'm using expect as my assertion library. For some of these tests I need to chain a large number of requests together, so the promises have been very helpful. However I'm noticing that my tests are now failing with a timeout (and no error message) rather than with the error message itself. As a simple example: it('[MESSAGES-1] cannot be posted

Unit Testing redux async function with Jest

▼魔方 西西 提交于 2019-12-11 04:24:01
问题 I'm pretty new to unit testing so please pardon any noobness. I have a file api.js which has all the API call functions for the app. Each function returns its promise. Here's how it looks: api.js const api = { getData() { return superagent .get(apiUrl) .query({ page: 1, }); }, } Now coming to the redux async action that i'm trying to test. It looks something like this: getDataAction.js export function getData(){ return dispatch => { api.getData() .end((err, data) => { if (err === null && data

Streaming data events aren't registered

给你一囗甜甜゛ 提交于 2019-12-11 03:42:38
问题 I'm using superagent to receive a notifications stream from a server require('superagent') .post('www.streaming.example.com') .type('application/json') .send({ foo: 'bar' }) .on('data', function(chunk) { console.log('chunk:' + chunk); // nothing shows up }) .on('readable', function() { console.log('new data in!'); // nothing shows up }) .pipe(process.stdout); // data is on the screen For some reason data and readable events aren't registered, hovewer I can pipe data to the sceeen. How can I

How to make superagent return a promise

房东的猫 提交于 2019-12-10 15:23:05
问题 I've been learning Node/Javascript, using promises from the start (I don't know how to not use promises and often wonder how others get along without them). So I sometimes need to "promisify" simple stuff like reading a file with fs : var readFile = function(path) { return new Promise(function(fulfill, reject) { fs.readFile(path, function(err, data) { if (err) { reject(err); } else { fulfill(data); } }); }); }; And that's been working great. Now I need to do the same with superagent , but the

Sending files over ajax (superagent) to a PHP backend (Laravel)

爱⌒轻易说出口 提交于 2019-12-08 09:40:03
问题 Recently I have been messing around with superagent in a project of mine and got to a road block. I am trying to send files via ajax to my Laravel PHP backend but I can't seem to receive anything on the backend side. I have been using superagents 'attach' method with no success. Javascript (ES6) createProject(input) { Request.post(domain + '/projects') .withCredentials() .field('project', input.project) // Truncated for brevity .attach('image', input.image) .end(function (err, res) { // Do

Testing post in bare Node.js app with Mocha and Superagent

久未见 提交于 2019-12-08 09:18:27
问题 I hope the day finds you well. So I'm trying to build some TDD chops in Node and to that end I've built a super bare bones app which runs a simple GET and POST request. All it does is serve the worlds most simple form, then take what the user enters into this form and put it on the screen. This is virgin Node, no frameworks involved. I'm using Mocha and Superagent for testing and am getting stuck on the POST test. Here's my app: var http = require('http'); var qs = require('querystring'); var