Comments (3)
Hey. My Solution is for AngularJs not for Angular.
For Angular we actually no longer use Restangular. We added a request interceptor to convert all gets to the override posts
import {HttpEvent, HttpHandler, HttpInterceptor, HttpParams, HttpRequest} from '@angular/common/http';
import {Injectable} from '@angular/core';
import {Observable} from 'rxjs';
import {LibString} from 'src/app/core/lib/string';
@Injectable()
export class GetAsPostInterceptor implements HttpInterceptor {
public intercept(request: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> {
if (
request.url
&& LibString.startsWith(request.url, '/api')
&& request.method
&& request.method.toUpperCase() === 'GET'
) {
let body: {[key: string]: any} = {};
request.params.keys().map((paramName: string) => {
body[paramName] = request.params.getAll(paramName);
body[paramName] = body[paramName].length === 1 ? body[paramName].pop() : body[paramName];
});
request = request.clone({
method: 'POST',
setHeaders: {
'X-HTTP-Method-Override': request.method
},
params: new HttpParams(),
body: body
});
}
return next.handle(request);
}
}
and in app.module.ts
import {GetAsPostInterceptor} from '.../get-as-post.interceptor';
@NgModule({
exports: [
],
imports: [
],
// All providers you need in AngularJS
providers: [
// Request interceptors, might be able to move them to the actual modules, but those are generated
{ provide: HTTP_INTERCEPTORS, useClass: GetAsPostInterceptor, multi: true },
]
})
export class AppModule implements DoBootstrap {
}
LibString
export class LibString {
public static startsWith(inputString: string, prefix: string): boolean {
return inputString.indexOf(prefix) === 0;
}
}
(edit) Only bug it has now is that if you add an array of [0] it's perceived as empty 🤷♀ didn't have time to fix it.
from ngx-restangular.
To be clear, ngx-Restangular is an angular component, and I believe that the change you made to Angular's Restangular is relevant here (thanks for that!)
The fact that your application doesn't use ngx-restangular (which is the Angular version of Restangular) is not really relevant - others do use ngx-restangular, and the fix/change is relevant to them.
thanks
from ngx-restangular.
Yeah, I understand, but as I said my pull request is on the AngularJS version. Hope they will implement it for you in the Angular version
from ngx-restangular.
Related Issues (20)
- How to send array in Request Payload ? HOT 1
- PUT on a sub-property of an element HOT 2
- Error npm install with git branch HOT 6
- Custom headers emptying the headers map HOT 1
- Not working with Angular 8 HOT 1
- Remove deep import of core.js 3 HOT 2
- Support type defintions for ngx-restangular HOT 1
- Angular 9 Upgrade HOT 17
- Integrate HTTP_INTERCEPTORS of Angular as FullRequestInterceptors
- Define dependencies in package.json?
- Should `@types/lodash` be a non-dev dependency? HOT 1
- Why was use of HttpClient explicitly removed? HOT 2
- set default headers after login HOT 1
- Should it add query string to route? HOT 2
- Is this project still being maintained? HOT 2
- AuthService Code
- Uncaught Error: Type RestangularModule does not have 'ɵmod' property. HOT 1
- ngx-restangular still being maintained? Community fork? HOT 1
- The bug in defaultResponseInterceptor
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 ngx-restangular.