How to use @angular/http - 10 common examples

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 gazbert / bxbot-ui-angular / src / app / model / bot / bot-http-data-promise.service.spec.ts View on Github external
it('should handle returning no Bot', async(inject([], () => {
            let resp = new Response(new ResponseOptions({status: 200, body: {data: []}}));
            backend.connections.subscribe((c: MockConnection) => c.mockRespond(resp));
            service.getBot(100) // unknown id
                .then(bot => expect(bot.id).not.toBeDefined('should have no Bot'));
        })));
    });
github sebastianhaas / medical-appointment-scheduling / src / app / api / api / appointment.service.ts View on Github external
public appointmentExistsHeadAppointmentsid(id: string, extraHttpRequestParams?: any): Observable {
        const path = this.basePath + `/appointments/${id}`;

        let queryParameters = new URLSearchParams();
        let headers = new Headers(this.defaultHeaders.values()); // https://github.com/angular/angular/issues/6845
        // verify required parameter 'id' is not null or undefined
        if (id === null || id === undefined) {
            throw new Error('Required parameter id was null or undefined when calling appointmentExistsHeadAppointmentsid.');
        }

        // to determine the Content-Type header
        let consumes: string[] = [
            'application/json', 
            'application/x-www-form-urlencoded', 
            'application/xml', 
            'text/xml'
        ];

        // to determine the Accept header
        let produces: string[] = [
            'application/json',
github ovh / cds / ui / src / app / service / http-service.service.ts View on Github external
getRequestOptionArgs(options?: RequestOptionsArgs): RequestOptionsArgs {
        if (options == null) {
            options = new RequestOptions();
        }
        if (options.headers == null) {
            options.headers = new Headers();
        }

        // ADD user AUTH
        let sessionToken = this._authStore.getSessionToken();
        if (sessionToken) {
            options.headers.append(this._authStore.localStorageSessionKey, sessionToken);
        } else {
            let user = this._authStore.getUser();
            if (user != null) {
                options.headers.append('Authorization', 'Basic ' + user.token);
            }
        }
        return options;
    }
}
github FINRAOS / herd-ui / src / app / core / services / user.service.ts View on Github external
getCurrentUser(username?: string, password?: string): Observable {
    if (this.conf.config.useBasicAuth && username && password) {
      this.apiConf.username = username;
      this.apiConf.password = password;
    }
    // the added timestamp of the query string forces legacy browsers to not cache the http response
    // for current user.  this fixes current user differentiated tests.
    const search = new URLSearchParams(`v=${Date.now()}`.toString());
    return this.currentUserApi.currentUserGetCurrentUserWithHttpInfo({search}).map((res) => {
      this.userAuthorizations = res.json();
      this._user.next(res.json());
      this.encryptedUserIdentifier = this.encryptionService.encryptAndGet((res.json() as UserAuthorizations).userId);
      return res.json();
    });
  }
github dotCMS / core-web / src / app / portlets / shared / dot-content-types-edit / components / fields / dot-content-type-fields-variables / services / dot-field-variables.service.spec.ts View on Github external
const field: DotCMSContentTypeField = {
            ...dotcmsContentTypeFieldBasicMock,
            contentTypeId: '1b',
            id: '1'
        };

        this.fieldVariableService.load(field).subscribe((variables: DotFieldVariable[]) => {
            expect(variables).toEqual(mockResponse.entity);
            expect(0).toBe(this.lastConnection.request.method); // 2 is GET method
            expect(this.lastConnection.request.url)
                .toContain(`v1/contenttype/${field.contentTypeId}/fields/id/${field.id}/variables`);
        });

        this.lastConnection.mockRespond(
            new Response(
                new ResponseOptions({
                    body: JSON.stringify(mockResponse)
                })
            )
        );
    });
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 ova2 / angular-development-with-primeng / chapter9 / crud-datatable / src / app / backend / fake-backend.ts View on Github external
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') &&
                connection.request.method === RequestMethod.Put) {
                let receivedEmployee = JSON.parse(connection.request.getBody());
                let clonedEmployee = Object.assign({}, receivedEmployee);
                let employeeWasFound = false;
                data.some((element: Employee, index: number) => {
                    if (element.id === clonedEmployee.id) {
                        data[index] = clonedEmployee;
                        employeeWasFound = true;
                        return true;
                    }
                });
                
                if (!employeeWasFound) {
                    connection.mockRespond(new Response(new ResponseOptions({
                        status: 400,
                        body: 'Employee could not be updated because was not found'
                    })));
github angular / angular / aio / content / examples / testing / src / app / model / http-hero.service.spec.ts View on Github external
beforeEach(() => {

      backend = TestBed.get(XHRBackend);
      http = TestBed.get(Http);

      service = new HttpHeroService(http);
      fakeHeroes = makeHeroData();
      let options = new ResponseOptions({status: 200, body: {data: fakeHeroes}});
      response = new Response(options);
    });
github RoyPlu / Flare / src / app / services / tinder.service.ts View on Github external
cloudmersiveDetect(form: FormGroup) {
        const headers = new Headers({
            'ApiKey': '59710ec3-24ee-4d4c-a90e-efb6170e2f50',
        });

        const options = new RequestOptions({
            headers: headers
        });

        console.log("cloudmersiveDetect");
        console.log(this.http.post("https://api.cloudmersive.com/image/recognize/describe", form ,options).map(res => res.json()));
        return this.http.post("https://api.cloudmersive.com/image/recognize/describe", form ,options).map(res => res.json());
    }