Skip to content

benhid/swapi-go

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

swapi-go

A simple Go backend for the Star Wars API (SWAPI), exposing REST endpoints to list people and planets from the Star Wars universe.

Getting Started

Prerequisites

Make sure you have the following installed:

  • Go 1.25+
  • Docker and Docker Compose (optional)
  • jq (optional, for parsing JSON in example commands)

Build & Run

Using Go

Build and start the server:

make run

Using Docker

Build and start the Docker container with:

docker compose up -d

The server will run at http://localhost:6969.

API usage

The backend exposes the following endpoints:

Method Endpoint Description
GET /people Retrieve a list of Star Wars characters
GET /planets Retrieve a list of Star Wars planets
GET /health Check server health

All data is fetched from SWAPI and cached in memory for better performance.

Query parameters

You can use query parameters to paginate, search, and sort results:

  • page – Page number (default: 1)
  • limit – Number of results per page (default: 15)
  • search – Filter results by name containing the search term (case-insensitive)
  • sort – Field to sort by (name or created, default: name)
  • order – Sort order (asc or desc, default: asc)

Example requests:

curl -X GET http://localhost:6969/people?limit=2&page=2 | jq
curl -X GET http://localhost:6969/people?page=3&limit=1&search=ma&sort=name&order=asc | jq
curl -X GET http://localhost:6969/people?search=fe&sort=created&order=desc | jq

Testing

Run tests with:

make test
# make test-integration

About

Go backend for the Star Wars API (SWAPI)

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published