Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
postWithPromise(apiUrl: string, body: any): Promise {
let headers = new Headers(
{
'Content-Type': 'application/json',
'Authorization': this.accessToken.token_type + ' ' + this.accessToken.access_token
});
// headers['Access-Control-Allow-Origin'] = '*'
let options = new RequestOptions(
{
method: RequestMethod.Post,
url: apiUrl,
headers: headers,
body: body
}
);
// this.spinnerService.show();
let request = this.http.request(apiUrl, options);
return request.toPromise()
.then(result => this.extractData(options, result
, this.spinnerService
))
.catch(errors => this.handleErrorPromise(options, errors
, this.spinnerService
));
}
extractData(request: RequestOptions, res: Response
setTimeout(() => {
// get all employees
if (connection.request.url.endsWith('/fake-backend/employees') &&
connection.request.method === RequestMethod.Get) {
connection.mockRespond(new Response(new ResponseOptions({
status: 200,
body: data
})));
return;
}
// create employee
if (connection.request.url.endsWith('/fake-backend/employees') &&
connection.request.method === RequestMethod.Post) {
let receivedEmployee = JSON.parse(connection.request.getBody());
let newEmployee = Object.assign(receivedEmployee, {id: uuid.generate()});
data[data.length] = newEmployee;
localStorage.setItem('employees', JSON.stringify(data));
connection.mockRespond(new Response(new ResponseOptions({
status: 200,
body: newEmployee
})));
return;
}
// update employee
if (connection.request.url.endsWith('/fake-backend/employees') &&
private requestMessages(): void {
this.coreWebService.requestView({
body: {
messagesKey: this.messageKeys
},
method: RequestMethod.Post,
url: this.i18nUrl,
}).pluck('i18nMessagesMap').subscribe(messages => {
this.messageKeys = [];
this.messagesLoaded = Object.assign({}, this.messagesLoaded, messages);
this._messageMap$.next(this.messagesLoaded);
});
}
}
public post(url: string, data: any, apiName?: string, headers?: any, params?: any): Observable {
return this.request({
method: RequestMethod.Post,
url: url,
data: data,
params: params,
headers: headers,
apiName: apiName
});
}
this.urlPrefix = this.databaseUrl;
if (type === undefined || type === '') {
type = 'local';
}
let headers = new Headers({
'Content-Type': 'application/json',
'Authorization': 'Basic ' +
btoa(userName + ':' + userPass)
});
let requestOptions = new RequestOptions({
headers: headers,
method: RequestMethod.Post
});
return Observable.create((observer: Observer) => {
this.authHttp.request(this.urlPrefix + 'database/' + this.encodedDatabaseName + '/' +
type + '/' + databaseType + this.urlSuffix,
requestOptions)
.subscribe(
res => {
this.setErrorMessage(undefined);
this.setDatabaseInfo(this.transformResponse(res));
observer.next(res);
observer.complete();
},
err => {
this.setErrorMessage('Connect error: ' + err.responseText);
this.setDatabaseInfo(undefined);
backend.connections.subscribe(conn => {
conn.mockRespond(new Response(new BaseResponseOptions()));
expect(conn.request.method).toEqual(RequestMethod.Post);
expect(conn.request.url).toEqual('/api/microposts');
expect(conn.request.json()).toEqual({
content: 'my post',
});
});
micropostService.create('my post').subscribe(() => {
save(pageIdentifier: string, dotLayout: DotLayout): Observable {
return this.coreWebService
.requestView({
body: dotLayout,
method: RequestMethod.Post,
url: `v1/page/${pageIdentifier}/layout`
})
.pipe(
pluck('entity'),
map((dotPageRenderResponse: DotPageRender.Parameters) => new DotPageRender(dotPageRenderResponse))
);
}
}
post(path: String, data: Object): Observable {
const opts: RequestOptions = new RequestOptions();
opts.method = RequestMethod.Post;
opts.headers = new Headers({ 'Content-Type': 'application/json' });
this.createAuthorizationHeader(opts.headers);
return this.http.post(
this.settingsStorageService.getSettings().site + path,
JSON.stringify(data),
opts
);
}
post(url: string, data: any, params: any): Observable {
if (!data) {
data = params;
params = {};
}
let options = new ApiGatewayOptions();
options.method = RequestMethod.Post;
options.url = url;
options.params = params;
options.data = data;
return this.request(options);
}
constructor(public endpointGuid: string, public createOrg: IUpdateOrganization) {
super();
this.options = new RequestOptions();
this.options.url = `organizations`;
this.options.method = RequestMethod.Post;
this.options.body = createOrg;
this.guid = createOrg.name;
}
actions = getActions('Organizations', 'Create Org');