Search code examples
angulartypescriptfeathersjs

angular , find data from the client using id (Angular Observable)


I want to call the api endpoint from the database from the client side and I am using observable.

The current code calls http://localhost:3030/humans/id?343 instead of http://localhost:3030/humans/343

what seem to be the issue on my query ? query: { id: 343 } ?

here I want to find human based on the id

findHuman(formGroup: FormGroup): Observable<Human[]> {
  return from(this.feathers.service('human').find<Human>({
    query: { id: 343 }
    }))
    .pipe(
      map((result) => result.data)
    );
}

Solution

  • This is what the get service method is used for:

    findHuman(formGroup: FormGroup): Observable<Human[]> {
      return from(this.feathers.service('human').get<Human>(343)
        .pipe(
          map((result) => result.data)
        );
    }
    

    For more information on how service methods map to URLs also see the REST client HTTP API.