api.service.ts
angular/examples/week03-04/src/app/shared/api.service.ts
// @ts-nocheck
import { Injectable, inject } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import { API_BASE_URL } from './api-token';
import { Observable } from 'rxjs';
export interface RegistrationRequest {
name: string;
email: string;
role: string;
newsletter: boolean;
password: string;
}
export interface RegistrationResponse {
receivedAt: string;
data: RegistrationRequest;
message: string;
}
@Injectable({ providedIn: 'root' })
export class ApiService {
private http = inject(HttpClient);
private baseUrl = inject(API_BASE_URL);
submitRegistration(payload: RegistrationRequest): Observable<RegistrationResponse> {
return this.http.post<RegistrationResponse>(`${this.baseUrl}/contact`, payload);
}
}
Related articles
server.js
server.js — javascript source code from the angular learning materials (angular/comprehensive-demo/server/server.js).
Read article →app.component.ts
app.component.ts — typescript source code from the angular learning materials (angular/comprehensive-demo/src/app/app.component.ts).
Read article →app.config.ts
app.config.ts — typescript source code from the angular learning materials (angular/comprehensive-demo/src/app/app.config.ts).
Read article →app.routes.ts
app.routes.ts — typescript source code from the angular learning materials (angular/comprehensive-demo/src/app/app.routes.ts).
Read article →auth.guard.ts
auth.guard.ts — typescript source code from the angular learning materials (angular/comprehensive-demo/src/app/core/guards/auth.guard.ts).
Read article →role.guard.ts
role.guard.ts — typescript source code from the angular learning materials (angular/comprehensive-demo/src/app/core/guards/role.guard.ts).
Read article →