Groups keyboard shortcuts have been updated
Dismiss
See shortcuts

Example for Creating Angular Services with Signals and Resources for API Interaction

31 views
Skip to first unread message

Eric Patton

unread,
Dec 21, 2024, 3:12:45 AM12/21/24
to Angular and AngularJS discussion

I'm looking to implement an Angular service that interacts with an enterprise RESTful API using Angular's new signal and resource features. Most of the examples I've found demonstrate making API calls directly within components with a signal for each input to that API call, but I want to adhere to best practices by encapsulating this logic within a dedicated service.

Here's the structure of my API responses:

export interface ApiResponse<T> { success: boolean; message: string; statusCode: number; data: T; }


Can anyone provide a simple example of how to use signals and the resource API with a GET and POST that take in parameters for a service?

I'm especially wondering how the input parameters would work. Surely you wouldn't need to make a computed signal (along with the other signals it references) for every single endpoint method.


I could also be looking at this completely wrong, and maybe these aren't the best things to use for it. Our team is pretty new to Angular, so we're still trying to figure out best practices so we can come up with a standard.

Reply all
Reply to author
Forward
0 new messages