Comments (13)
Hey,
What are you getting in the data? Have you logged it? Or it's not entering in the callback?
from restangular.
The callback is not the response from the server, it looks like its just the post-data. But I need the server-response with id etc.
from restangular.
What Restangular does is the following:
- When making a POST or PUT, if the server returns something, that "something" is used.
- If the server doesn't return anything, then we use the parameter used for the post.
I've just added new test cases testing this:
- https://github.com/mgonto/restangular/blob/master/test/restangularSpec.js#L117
- https://github.com/mgonto/restangular/blob/master/test/restangularSpec.js#L138
As you can see, one uses something from the server, the other one the one as a parameter.
Can you please check that your server is indeed responding something?
Thanks!
from restangular.
Hey :)
As you can see, the server response with a json object:
http://i.imagebanana.com/img/gb5gkzul/response.png
And what I get on the callback with console.log(data) is this:
http://i.imagebanana.com/img/4lw7jff3/log.png
This is not the server response (id is missing)
from restangular.
Okey, that's weird!
The "magic" is in this line:
https://github.com/mgonto/restangular/blob/master/dist/restangular.js#L282
In there, can you tell me:
- Value of resData?
- Result of calling the responseExtractor method? As you can see there, it does the responseExtractor and if that returns undefined, it uses the object sent as a parameter.
Sorry for all the questions, but I don't really don't know what's going on and it's not happening on me (Typical excuse, huh? hahahaha)
from restangular.
Also, have you added some responseExtractor
or responseInterceptor
?
from restangular.
Maybe it's because of setResponseExtractor?
var app = angular.module('myTodo', ['ngResource', 'restangular']);
app.config(function(RestangularProvider) {
RestangularProvider.setBaseUrl('/api/v1');
RestangularProvider.setListTypeIsArray(false);
RestangularProvider.setResponseExtractor(function(response, operation) {
return response.objects;
});
});
from restangular.
That's the reason. So, for your lists, you want to get the .objects and for the rest you're returning the element itself?
from restangular.
Change the response extractor to:
RestangularProvider.setResponseExtractor(function(response, operation) {
if (operation === "getList") {
return response.objects;
} else {
return response;
}
});
That should work. For collections you return response, for the rest, you return the response itself :)
from restangular.
Yes. It's because the result of django-tastypie looks like this, for example:
{
"meta": {
"limit": 20,
"next": null,
"offset": 0,
"previous": null,
"total_count": 2
},
"objects": [{
"body": "Welcome to my blog!",
"id": "1",
"pub_date": "2011-05-20T00:46:38",
"resource_uri": "/api/v1/entry/1/",
"slug": "first-post",
"title": "First Post",
"user": "/api/v1/user/1/"
},
{
"body": "Well, it's been awhile and I still haven't updated. ",
"id": "2",
"pub_date": "2011-05-21T00:46:58",
"resource_uri": "/api/v1/entry/2/",
"slug": "second-post",
"title": "Second Post",
"user": "/api/v1/user/1/"
}]
}
from restangular.
Woha! Thanks!!!
It's working now.
Thank you 👍
from restangular.
Okey great!
I think you can use what I sent you before.
For getList you get the "objects" and for the rest, you just return response. Also, maybe you can like this:
if (operation === "getList") {
var retObject = response.objects;
retObject.meta = response.meta;
return retObject;
} else {
return response;
}
That way you can have an array for all objects and it also has a field for your meta if you need it later :)
from restangular.
Awesome :). I'm glad it work. Check the last response, you might want to save the meta as well for later usage :).
I'm closing this then.
Thanks for using the library!
from restangular.
Related Issues (20)
- Error when injecting restangular with angular 1.6.4 HOT 2
- Nested Services or Nested Configuration
- $remove() id as query parameter HOT 1
- new web app using restangular - www.connecttal.com -
- Element.plain() behaves differently compared to Retangular.stripRestangular
- How to make sync call?
- How to set array of object as parameters using customGET ?
- Did restangular support handling text/html or text/csv response?
- Response for getList SHOULD be an array and not an object or something else HOT 1
- make etag a strong etag when used in if-None-Match HOT 1
- Cancel request - Angular 1.5 HOT 1
- getList() response Json object loss some data
- How do I append query parameter with restangular.oneUrl()? HOT 1
- Details of HTTP request sent by put method ?
- Group by count
- addFullRequestInterceptor has empty headers object
- TypeError: Converting circular structure to JSON while <restangular-object>.put() HOT 1
- Multiple remove on Restangular
- Deprecated?
- Support DELETE method with body
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from restangular.