Code Monkey home page Code Monkey logo

Comments (3)

DracoBlue avatar DracoBlue commented on May 27, 2024

I thought about this, too. But there is a method called HttpAgent#clone, which can be used to generate a copy of the agent.

I use it like this (to delete multiple products by id):

var products = new HttpAgent('/api').navigate('products');

[1,2,3,45].forEach(function(id) {
   var copy = products.clone();
   copy.navigate({"id": id}, 'self').delete();
});

from hateoas-client-js.

jamesfoster avatar jamesfoster commented on May 27, 2024

I saw the .clone() method and realised this was its purpose. I just feel that if I give you a HttpAgent for products you should be able to call it and get products.

As it is I could call navigate and that agent I gave you no longer points to what you think it points to.

Do you support templates URLs?

{
  "_links": {
    "product": { "href": "/api/product/{id}", "isTemplated": true }
  }
}

Then agent.navigate('product', {"id": 1}) would generate /api/product/1

??

On 30 Jun 2014, at 20:35, DracoBlue [email protected] wrote:

I thought about this, too. But there is a method called HttpAgent#clone, which can be used to generate a copy of the agent.

I use it like this (to delete multiple products by id):

var products = new HttpAgent('/api').navigate('products');

[1,2,3,45].forEach(function(id) {
var copy = products.clone();
copy.navigate({"id": id}, 'self').delete();
});

Reply to this email directly or view it on GitHub.

from hateoas-client-js.

DracoBlue avatar DracoBlue commented on May 27, 2024

Nope. Templated URLs are not supported, yet.

If you do:

agent.navigate('products', {'id': id});

it is the same like:

agent.navigate('products')
agent.navigate{'id': id});

It will fetch products and filter all results for an entity with the
property id set to the desired value.

See
https://github.com/DracoBlue/hateoas-client-js/blob/master/example/buy_coffee.html
for
an example.

I know that this is not templated URIs, but that's the reason why the
second parameter for navigate is already taken ;)

If you want to append query parameters, you can do it like this:

agent.navigate('product').get(function(response) {
}, {"id": id});

This will append ?id=1225 to the product link of the agent.

from hateoas-client-js.

Related Issues (7)

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.