Question

I'm using AngularJS Restangular to make a POST to a mock REST API I have created on http://www.mockable.io

My Code is very simple...

RestangularProvider.setBaseUrl("http://demo1461049.mockable.io");


var newBranch = {"test":"test"}

var branches = Restangular.all("branches");

branches.post(newBranch);

The first problem I noticed is that it is doing an OPTIONS request instead of a POST request. I have seen people saying that this is because it is doing a CORS request (Localhost to mockable.io). I haven't managed to work out exactly how CORS works but I set up Mocakable so it would accept OPTIONS. I now get the following error...

 Request header field Content-Type is not allowed by Access-Control-Allow-Headers.

I have seen a few threads about this error but they are all from people trying to create their own API (normally ASP.NET). Is this an option that I need to set but cannot because Mockable doesn't allow you to? That would seem strange as the whole point of Mockable is that you make cross-origin requests to it.

Any help would really be appreciated.

Was it helpful?

Solution

The error you get is a server response. Unless you can edit what headers the server allows in regards to CORS your in trobule.

I'am not using mockable myself but they seem to have CORS support so I would be surprised if they didnt have an option to edit CORS headers.

An example for a CORS implementation I have for a private API which is the most common headers:

CORS_ALLOW_HEADERS = (
'x-requested-with',
'content-type',
'accept',
'origin',
'authorization',
)

Find something similiar for mockable and your home-safe

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top