Giter Site home page Giter Site logo

Recursive calls Examples about api-easy HOT 8 OPEN

vowsjs avatar vowsjs commented on July 19, 2024
Recursive calls Examples

from api-easy.

Comments (8)

ajostergaard avatar ajostergaard commented on July 19, 2024

+1

from api-easy.

davistan avatar davistan commented on July 19, 2024

👍

from api-easy.

gerardobort avatar gerardobort commented on July 19, 2024

👍

from api-easy.

joehler avatar joehler commented on July 19, 2024

I've run into this also. My solution for the token was to get the token and then use the 'before' function to set the token in subsequent outgoing requests.

.post(authUrl, postObject)
  .expect(200)
  .expect('should respond with the authorize token', function (err, res, body) {
    var result = JSON.parse(body);
    assert.isNotNull(result.access_token);

    // Before each subsequent call, set the authorization header
    suite.before('setAuth', function (outgoing) {
      outgoing.headers['Authorization'] = result.access_token;
      return outgoing;
    });
   }) 

from api-easy.

gerardobort avatar gerardobort commented on July 19, 2024

thanks @joehler !! that helped!... the only thing is that when running with --spec param, the api-easy log is misleading because I'm modifying the outgoing.uri and it shows the old one.

from api-easy.

exocom avatar exocom commented on July 19, 2024

I'm having a similar issue, I can't figure out how to pass a value from the previous call to the path of the next call.

I want to POST an item them I want to do a DELETE with the id that was returned from the POST.

var partId = null;

.post('/parts', {name:'foo'})
  .expect(200)
  .expect('should respond with 1 part', function (err, res, body) {
    var result = JSON.parse(body);

    assert.equal(result.name, 'foo');
    assert.equal(typeof result.id === 'string',true);

    partId = result.id;
   })

.then()

.del('/parts/' + partId)
  .expect(200)

What am I doing wrong?

from api-easy.

stevendearborn avatar stevendearborn commented on July 19, 2024

It seems that the suite.del has already been initialized the the null value of the partId already and no further modification is do with it by the time it executes.

The only way is to add this to the end of subsequent sequential calls (i.e. using next() ) by using suite.before to append the partId to the URL passed implicitly to suite.del.

I am trying this now, since this would be a very common pattern, but I also need to restore/remove the appended id when I am done.

from api-easy.

piercus avatar piercus commented on July 19, 2024

this is a trick, but i'm posting anyway, in case someone has same issue :

var request = require("request");

...

.del(function(outgoing, callback){
     outgoing.uri = outgoing.uri+'parts/' + partId
     request(outgoing, callback)
})

from api-easy.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.