sendCommand(command: string): Observable<any> { return this.http.get<any>(`/api/command`, { params: {"command": command} }); }
Running
sendCommand("test")
will send a HTTP GET request to /api/command?command=test
.
Full service example
import { HttpClient } from '@angular/common/http'; import { Injectable } from '@angular/core'; import { Observable } from 'rxjs'; @Injectable({ providedIn: 'root' }) export class CommandService { constructor(private http: HttpClient) { } sendSerialCommand(command: string): Observable<any> { return this.http.get<any>(`/api/command`, { params: {"command": command} }); } }