Comments (8)
You're right, there's no way to post on "root" element. This needs to be added.
However, doing Restangular.all("accounts") doesn't really fetch anything, it just creates Restangular object, so, the implementation would be something like this:
Restangular.all("accounts").getList().then(function(accounts) {
accounts.post({... data ...});
});
from restangular.
Actually, I'm thinking in implementing both:
// Option 1 on Root Restangular Obj
Restangular.all("accounts").post({data});
//Option 2 for every Restangular collection
Restangular.all("accounts").getList().then(function(accounts) {
accounts.post({... data ...});
});
from restangular.
Oopsy, forgot the "getList()" in my sample, corrected.
+1 for the 1st option since you might probably want to directly do a POST to the collection without fetching it with a GET. Also supporting the 2nd option would be quite nice.
from restangular.
I'll implement both :). I'll try to do this tomorrow.
Thanks for the input man!
from restangular.
Also uncommented test, and added another one. Tests passing.
from restangular.
Nice. I've taken a quick look at your code and here is some feedback. Should we limit this approach to only a few HTTP methods? Or should we support them all? It's not that impossible that a user might want to perform a DELETE on a collection in order to remove all elements. Or use PUT instead of POST to create new elements (not really good IMO but that's its problem).
In fact, even the GET can be done (I'm talking about the one returning an object and not an array). In particular for people having a wrapper around their collections and wanting to retrieve this wrapper and not the real data (because in that case, they could use the extractor you already coded).
With no restriction, you will have no unhappy users ;-)
Also, I will improve tests when all work will be merged and Lodash available.
from restangular.
Hey,
I actually think that this methods as "default" wrappers are ok.
I'm planning to add a "customOPERATION" method on both collections and elements like:
account.customPOST(path, params, headers)
where path can be either null or a value, so that you could do POST /accounts/messages
Same for elements, so that users can have the flexibility to do whatever they want, besides the "defaults" from Angular.
from restangular.
It'd be implementing: #19
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.