SuperAPI AI Directory

d2-02-api-service

Coding & development

View repository

Updated 10-16 02:08

About this skill

Day 2 · Step 2 — API service

If the entity isn't already established in this conversation, ask which entity (it must match the one exposed by up-api's CRUD endpoints).

up-app/src/app/services/<entity>.service.ts:

import { Injectable } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import { Observable } from 'rxjs';

export interface <Entity> {
  id?: number;
  // one field per column from the Day 1 entity spec
}

@Injectable({ providedIn: 'root' }) export class Service { private base = 'http://localhost:8080/api/s'; constructor(private http: HttpClient) {}

getAll(): Observable<[]> { return this.http.get<[]>(this.base); } getById(id: number): Observable<> { return this.http.get<>(${this.base}/detail/${id}); } save(item: ): Observable<> { return this.http.post<>(${this.base}/save, item); } update(id: number, item: ): Observable<> { return this.http.put<>(${this.base}/update/${id}, item); } delete(id: number): Observable { return this.http.delete(${this.base}/${id}); } }


Register `provideHttpClient()` in `app.config.ts` if it isn't already there. No redeploy needed for this step.