Giter VIP home page Giter VIP logo

rest's People

Contributors

briancavalier avatar gogamoga avatar irrelon avatar jamesmanning avatar jiangty-addepar avatar mjackson avatar mosch avatar optical avatar parlarjb avatar pdehaan avatar phillipj avatar scothis avatar srl295 avatar unscriptable avatar wonderb0lt avatar wwwdata avatar zeitiger avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

rest's Issues

Requests with credentials (add withCredentials to xhr)

How should I do an XHR/XDR that has withCredentials set to true? Basically I need it to send cookies along with the request (cookies were set server-side).

In plain JS I can do:

var xhr = new XMLHttpRequest();
xhr.withCredentials = true;

Here's what I tried with rest.js:

var myFirstInterceptor = interceptor({
    request: function handleRequest(request, config) {
        request.withCredentials = true;
        return request;
    }
});

var client = rest.chain(myFirstInterceptor);
client({path: '/foo'});

However, the request object here is not the "raw" XMLHTTPRequest, nor is the property copied onto the actual XHR object.

Can you help me out here? :-)

Configuration DSL for wire.js

Configuring rest clients with wire.js is currently a pain, even with the current wire plugin. It needs to be much easier to wrap an client with more interceptors.

Current syntax:

client: {
    create: {
        module: 'rest/interceptor/hateoas',
        args: [
            {
                create: {
                    module: 'rest/interceptor/entity',
                    args: {
                        create: {
                            module: 'rest/interceptor/location',
                            args: { $ref: 'client!', mime: 'application/json', entity: false }
                        }
                    }
                }
            },
            { target: '' }
        ]
    }
}

A proposed syntax:

client: {
    rest: {
        parent: { $ref: 'baseClient' },
        interceptors: [
            { module: 'rest/interceptor/mime', config: { mime: 'application/json' } },
            { module: 'rest/interceptor/location' },
            { module: 'rest/interceptor/entity' },
            { module: 'rest/interceptor/hateoas', config: { target: '' } }
        ]
    }
}

the parent/baseClient is provided as an example of how to wrap another client. It should be removed form this example for functional equivalence with the current syntax.

Shortcuts to this syntax could also be introduced:

  • use just the interceptors array if the default client should be the chain's parent
  • use just the module id string if no config is needed
  • use a shortcut namespace for interceptor modules ids (ie 'rest:entity' -> 'rest/interceptor/entity')

Cookie jar interceptor

Cookies are commonly used to track clients across requests. Many APIs use cookies to track authentication after subsequent requests.

While browsers will automatically track cookies. Node does not provide such a facility.

Note: Programatic setting and reading cookies from HTTP headers is forbidden by the XHR spec. The cookie jar has no hope of ever working in browsers.

interceptor config does not like $ref??

Refuses to work:

define({
    somePrefix: "whatever",
    client: {
        rest: {
            interceptors: [
                {
                    module: "rest/interceptor/pathPrefix",
                    config: {
                      prefix: { $ref: "somePrefix" }
                    }
                }
            ]
        }
    }
})

.chain() missing from defaultClient in 1.0.1

Reported by @monteslu on IRC. In rest.js now, it returns defaultClient as a wrapper around the actual client, but I don't think that defaultClient.chain is provided. That causes existing code that does rest(config).chain(...) to fail.

A workaround for existing code is to change it to rest(config).getDefaultClient().chain(...).

A possible fix might be to add a delegating chain to defaultClient just before the return defaultClient:

defaultClient.chain = function delegateChain() {
    return client.chain.apply(defaultClient, arguments);
};

timeout interceptor does not set the timeout value on the XMLHttpRequest

when I use the timeout interceptor in the with the xhr client (XMLHttpRequest) it does not register the timeout property on the request.

So if a request takes very long and the promise returns, it still leaves the XMLHttpRequest open. In this case the browser will not have a timeout at all. In my case this caused IE8 to not send any requests anymore.

IMO the browser should be aware of the intended timeout anyways.

request interceptors are executed in reverse order

Here's another issue of developer surprise, if not a bug: interceptor request handlers are executed in the opposite order that they are chained in. Is this the intended behavior? If it is, it is not obvious and should be documented somewhere.

plugins to $plugins

wire docs say to use $plugins instead of plugins. Shouldnt it be updated in rest docs as well?

Detect redirect loops for the location interceptor

The location interceptor will happily follow redirect loops, potentially forever. We should track the URLs that are being requested and error out if a cycle is detected. This behavior should be on by default, but disabled via configuration.

Reenable sauce labs test for IE 6 and 7

These browsers produce false positives when reporting back the test results.

The test suite finishes successful, but the summary text is not the expected value.

Not sure how to do chunked POST/PUT

The documentation is not clear how/or whether we can do a chunked put/post of large file to rest API. The problem is I have a huge file ~110MB which I would like to post to a server. Any ideas? Or is there a way to add support for that?

Use of beget() for config object complicates logging/debugging

Because the beget() function returns an object with the original object as the new object's prototype instead of attaching the properties directly to the new object, operations such as console.log and JSON.stringify do not work as expected on objects produced by beget(). More concretely, the config object that is passed around in an interceptor hides its properties from console.log and JSON.stringify.

I did a quick and dirty test using a simpler approach with a flat object that seems like it could work just as well, at least for the interceptor's config object:

function clone(obj, props) {
    var tmp = {};
    mixin(tmp, obj);
    if (props) {
        mixin(tmp, props);
    }
    return tmp;
}

I can see that this would be slightly less performant with a larger, more complex object, but the difference would be small. If it is not feasible to change the implementation, I think it would be worth at least mentioning the quirks of beget() and therefore the interceptor config object, because its surprising and unexpected behavior makes writing custom interceptors more challenging.

I'll mention, since it could be useful to others, that I am using the following in my custom interceptor for debugging purposes. Note that this negates any performance advantages of using prototypal inheritance inside beget():

init: function(config){
    for (var k in config) config[k] = config[k];
    ...
}

Indicate the originating client for a request

This is useful for interceptor that need to initiative a subsequent request. Currently the best they can do is to reuse themselves, or ask the user to explicitly override the client. Often it would be better to reuse the full client interceptor chain.

XDomainRequest interceptor

IE 8 and 9 do not implicitly support cross origin requests via CORS. The XDomainRequest object is similar to the XMLHttpRequest object but can make cross origin requests.

We should provide an interceptor that will automatically switch to XDomainRequest when necessary.

Hateoas links should return the same promises on repeat access

Currently, the boundaries of the object graph managed by the hateoas interceptor return a promise for the related resource each time the property is accessed. This is counter intuitive to normal property access which would return the same object.

Async

Hi,

Is it possible to do an synchronous reques?

I didn't find an interceptor or setting anywhere.

The XHR client has async "true" hard coded.

Cheers,
Jose

Timeout interceptor

Cancel the request if a response is not received within the specified time

IE8

Hi,

Do you know if REST is supposed to work with IE8 and if its been tested with IE8? Currently it works in IE9+ but not 8.

Jose

RestStore without dojo

It should be possible to use RestStore without pulling in 'all' of dojo. RestStore currently pulls in dojo/store/util/QueryResults, this is a convenience util and isn't strictly necessary.

Consider removing QueryResult from the RestStore, or introduce a 'SimpleRestStore' that contains the core RestStore functionality without the dojo dependency.

Feedback request for restjs inside Spring Data REST

I'm working on a dynamic javascript library inside Spring Data REST, the project that automatically exports REST endpoints. The idea is to provide a JS library instead of requiring the dev to write their own RESTful handler. It would be available at /jsclient/{library}, where currently I've coded /jsclient/jquery. I would also like to code /jsclient/restjs. I'm interested in feedback on how to best code a restjs version of this.

You can see my work on a branch at https://github.com/gregturn/spring-data-rest/commits/dynamic-javascript. The latest commit with my work is at gregturn/spring-data-rest@4e5ecdb. If you scroll past all the log statements, you'll find some templated javascript that is used to generate jquery-specific code like this:

var sdr = {
    personRepository: {
        findAll: function(){
            return $.get('/people');
        },
        create: function(obj){
            return $.ajax({
                type: 'POST',
                url: '/people',
                data: JSON.stringify(obj),
                contentType: 'application/json'
            });
        },
        replace: function(id, obj){
            return $.ajax({
                type: 'PUT',
                url: '/people/' + id,
                data: JSON.stringify(obj),
                contentType: 'application/json'
            });
        },
        update: function(id, obj){
            return $.ajax({
                type: 'PATCH',
                url: '/people/' + id,
                data: JSON.stringify(obj),
                contentType: 'application/json'
            });
        },
        "delete": function(id){
            return $.ajax({
                type: 'DELETE',
                url: '/people/' + id
            });
        },
        findByLastName: function(name){
            return $.get('/people/search/findByLastName', { name: name });
        }
    }
};

What would be a good/similar solution using restjs?

JSONP client error in IE8

The "rest/client/jsonp" module is throwing a generic "Object doesn't support this action" error in IE8 when making a JSONP request.

@unscriptable narrowed the problem down to something in here https://github.com/cujojs/rest/blob/master/client/jsonp.js#L106-L108. If i remove line 107 script.onerror(e); i no longer saw the error.

One thing to note is that the request is successfully returning from the server and rest is not failing the request, just an error is being thrown.

HTTP 1.1 cache interceptor

Implement a client side HTTP 1.1 compliant cache as an interceptor. Browsers automatically provide a cache, but Node does not.

The low level cache impl should be a plugable strategy.

mime interceptor chokes if there is more than one Content-Type response header

Hey Scott,

I don't know how you want to handle this, but I just encountered a fun one: the XHR shim in Intel's XDK (Cordova-based mobile app environment) duplicates all response headers. (Actually, they're not quite duplicates: one is Proper-Case, the other is lower-case.)

This is obviously a bug in their shim. However, I was wondering if this could happen in non-buggy situations? If not, just close this. :)

-- John

Line of interest: https://github.com/cujojs/rest/blob/master/interceptor/mime.js#L79

Don't make a request if it has been cancelled

It's currently possible for a client to make a request even if the response has already been cancelled. This behavior is currently exhibited with the timeout and retry interceptors.

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.