How to use the @angular/http.RequestMethod.Post function in @angular/http

To help you get started, we’ve selected a few @angular/http examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github Swastika-IO / sio.core / src / Swastika.IO.Core / ClientApp / app / areas / portal / areas / cms / service.helper.ts View on Github external
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
github ova2 / angular-development-with-primeng / chapter9 / crud-datatable / src / app / backend / fake-backend.ts View on Github external
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') &&
github dotCMS / core-web / src / app / api / services / messages-service.ts View on Github external
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);
        });
    }
}
github outcobra / outstanding-cobra / frontend / src / app / core / http / http-interceptor.ts View on Github external
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
        });
    }
github bulktrade / SMSC / modules / admin / src / app / orientdb / orientdb.service.ts View on Github external
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);
github springboot-angular2-tutorial / angular2-app / src / app / core / services / micropost.service.spec.ts View on Github external
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(() => {
github dotCMS / core-web / src / app / api / services / dot-page-layout / dot-page-layout.service.ts View on Github external
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))
            );
    }
}
github dotCMS / core-web / projects / dotcms-js / src / lib / core / util / http.service.ts View on Github external
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
        );
    }
github asadsahi / AspNetCoreSpa / Client / modules / shared / services / api-gateway.service.ts View on Github external
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);
    }
github cloudfoundry / stratos / src / frontend / packages / cloud-foundry / src / actions / organization.actions.ts View on Github external
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');