Documentation Index
Fetch the complete documentation index at: https://mintlify.com/dreancaste/TriviaPP/llms.txt
Use this file to discover all available pages before exploring further.
SwapiService is a lightweight HTTP client that converts Angular’s Observable-based HttpClient calls into Promises via RxJS firstValueFrom. It targets the community-hosted SWAPI mirror at https://swapi.py4e.com/api and exposes methods for fetching paginated people and planet lists, individual resource records by ID, the complete films catalogue, and arbitrary SWAPI URLs for use in relation-resolution patterns (such as following a character’s homeworld URL).
Constructor / Dependencies
| Dependency | Token | Role |
|---|---|---|
HttpClient | @angular/common/http | Issues all HTTP GET requests |
HttpClientModule (or provideHttpClient() in standalone bootstrapping) must be registered in the application providers for SwapiService to function.
Methods
All methods returnPromise<any> and resolve with the raw JSON body from the SWAPI response. They reject if the HTTP request fails.
getPeople()
Fetches a paginated list of Star Wars characters.
The page number to fetch. Defaults to
1. SWAPI returns up to 10 results per page.getPerson()
Fetches a single character by their SWAPI numeric ID.
The SWAPI person ID (e.g.
"1" for Luke Skywalker).getPlanets()
Fetches a paginated list of Star Wars planets.
The page number to fetch. Defaults to
1.name, climate, terrain, population, and a list of residents URLs.
getPlanet()
Fetches a single planet by its SWAPI numeric ID.
The SWAPI planet ID (e.g.
"1" for Tatooine).getFilms()
Fetches the complete Star Wars films catalogue. SWAPI returns all films in a single response (no pagination).
title, director, producer, release_date, and episode_id.
getFilm()
Fetches a single film by its SWAPI numeric ID.
The SWAPI film ID (e.g.
"1" for A New Hope).getByUrl()
Resolves any fully-qualified SWAPI resource URL. This is the core of the homeworld-resolution pattern used by TriviaService — SWAPI embeds URLs (not IDs) in related-resource fields such as homeworld, residents, and films.
A full SWAPI resource URL, e.g.
"https://swapi.py4e.com/api/planets/1/".Usage Example
The following snippet mirrors howTriviaService uses SwapiService internally to build a “homeworld” question for a random character.