Skip to content

BaseApiService

reference
1 min readUpdated

Kind: Class

Source: Pams/Web/Pams.WebApp/Client/app/core/services/api/base-api.service.ts (line 12)

Part of: Pams

BaseApiService is a generic base class for client-side API calls that return RxJS Observable values. It groups collection retrieval, item retrieval, deletion, saving, ID generation, and error handling for application services.

Implements: IApi

Methods

MethodSignatureReturns
getget(queryParams: any[])Observable<T[]>
getByIdgetById(id: number)Observable<T>
deletedelete(id: number)Observable<{}>
savesave(item: T, queryParams: any[])Observable<T>
getNewIdgetNewId()void
handleErrorhandleError(error: Response)void

Properties

PropertyType
keyNamestring
resourceNamestring
headersany
headersPostany
basePathany
entityT

Diagram

mermaid
graph LR
    Consumer[Component or Service] --> BaseApiService
    BaseApiService --> Get[get]
    BaseApiService --> GetById[getById]
    BaseApiService --> Save[save]
    BaseApiService --> Delete[delete]
    BaseApiService --> NewId[getNewId]
    BaseApiService --> Error[handleError]
    Get --> Observable
    GetById --> Observable
    Save --> Observable
    Delete --> Observable

Usage

ts
import { BaseApiService } from './core/services/api/base-api.service';

interface Project {
  id: string;
  name: string;
}

declare const projectApi: BaseApiService<Project>;

projectApi.get().subscribe({
  next: (projects) => console.log(projects),
  error: (error) => console.error(error)
});

projectApi.save().subscribe({
  next: (project) => console.log(project),
  error: (error) => console.error(error)
});

AI Coding Instructions

  • Extend BaseApiService with the domain model type for each API resource.
  • Keep API method return values as Observable values; subscribe in components or other consumer boundaries.
  • Follow the existing get, getById, save, and delete methods instead of duplicating request and error-handling logic.
  • Keep resource-specific endpoint configuration and model mapping in the service that extends this class.

Used by

50 references from 50 files. Each is a place in this repository where the symbol is actually used — go read one rather than trusting an example.

Imported by (50)

  • BaseEditPams/Web/Pams.WebApp/Client/app/core/components/base-edit.component.ts:1
  • CoreModulePams/Web/Pams.WebApp/Client/app/core/core.module.ts:1
  • AddressTypeServicePams/Web/Pams.WebApp/Client/app/services/common/address-type.service.ts:1
  • AddressServicePams/Web/Pams.WebApp/Client/app/services/common/address.service.ts:1
  • BookingTargetServicePams/Web/Pams.WebApp/Client/app/services/common/booking-target.service.ts:1
  • CategoryServicePams/Web/Pams.WebApp/Client/app/services/common/category.service.ts:1
  • CityServicePams/Web/Pams.WebApp/Client/app/services/common/city.service.ts:1
  • ClientTypeServicePams/Web/Pams.WebApp/Client/app/services/common/client-type.service.ts:1

…and 42 more.

Was this page helpful?

Download as PDF