marmelab / FakeRest

Patch fetch/XMLHttpRequest to fake a REST API server in the browser, based on JSON data.
MIT License
439 stars 48 forks source link

Validation interceptors #2

Closed kendarorg closed 4 months ago

kendarorg commented 9 years ago

Hi, it would be nice to allow, parallel to the declaration of data, the declaration of a filter for each data block, to allow the simulation of validation errors and things like this:

restServer.initInterceptors({
    'customers': [
        { post: function(xhr,data,defaultHandler){
                       if(data.id < 0){
                              return {status:500,body:"WrongId"};
                      }
                      return defaultHandler(xhr,data)
        }}
    ]
});
fzaninotto commented 9 years ago

Great idea! I'm not sure it should be an interceptor of a new method added to the server, but it'd definitely be useful.

kendarorg commented 9 years ago

Hi Francois, i did a fork on github.com/kendarorg with a possible implementation (and updated readme...), it s only a proof of concept and i would need a deeper analisys. Btw after monday i ll manage to prepare a pull request with tests etc :) Enrico

On April 3, 2015 5:32:09 PM GMT+02:00, Francois Zaninotto notifications@github.com wrote:

Great idea! I'm not sure it should be an interceptor of a new method added to the server, but it'd definitely be useful.


Reply to this email directly or view it on GitHub: https://github.com/marmelab/FakeRest/issues/2#issuecomment-89324986

Sent from my Android phone with K-9 Mail. Please excuse my brevity.

djhi commented 5 months ago

What do you think about modifying the request interceptors so that they could throw a response? RemixRun style

fzaninotto commented 4 months ago

Implemented in #72