https://github.com/peterhellberg/swapi
A SWAPI client written in Go
https://github.com/peterhellberg/swapi
Last synced: 6 months ago
JSON representation
A SWAPI client written in Go
- Host: GitHub
- URL: https://github.com/peterhellberg/swapi
- Owner: peterhellberg
- Created: 2014-12-22T16:10:44.000Z (about 11 years ago)
- Default Branch: master
- Last Pushed: 2023-02-22T13:44:02.000Z (almost 3 years ago)
- Last Synced: 2025-08-14T14:02:25.112Z (6 months ago)
- Language: Go
- Homepage: https://swapi.dev
- Size: 32.2 KB
- Stars: 32
- Watchers: 2
- Forks: 8
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
A [SWAPI](http://swapi.dev) client written in Go
================================================
[](https://github.com/peterhellberg/swapi/actions/workflows/test.yml)
[](https://goreportcard.com/report/github.com/peterhellberg/swapi)
[](https://godoc.org/github.com/peterhellberg/swapi)
[](https://github.com/peterhellberg/swapi#license-mit)
## Installation
```bash
go get -u github.com/peterhellberg/swapi
```
## Examples
### atst.go
```go
package main
import (
"context"
"fmt"
"github.com/peterhellberg/swapi"
)
func main() {
c := swapi.DefaultClient
if atst, err := c.Vehicle(context.Background(), 19); err == nil {
fmt.Println("name: ", atst.Name)
fmt.Println("model:", atst.Model)
}
}
```
## Command line tool
### Installation
```bash
go install github.com/peterhellberg/swapi/cmd/swapi@latest
```
### Usage
```bash
Commands:
film [id]
person [id]
planet [id]
species [id]
starship [id]
vehicle [id]
films
people
planets
films
species
vehicles
starships
```
```json
$ swapi planet 1
{
"name": "Tatooine",
"rotation_period": "23",
"orbital_period": "304",
"diameter": "10465",
"climate": "arid",
"gravity": "1 standard",
"terrain": "desert",
"surface_water": "1",
"population": "200000",
"residents": [
"http://swapi.dev/api/people/1/",
"http://swapi.dev/api/people/2/",
"http://swapi.dev/api/people/4/",
"http://swapi.dev/api/people/6/",
"http://swapi.dev/api/people/7/",
"http://swapi.dev/api/people/8/",
"http://swapi.dev/api/people/9/",
"http://swapi.dev/api/people/11/",
"http://swapi.dev/api/people/43/",
"http://swapi.dev/api/people/62/"
],
"films": [
"http://swapi.dev/api/films/1/",
"http://swapi.dev/api/films/3/",
"http://swapi.dev/api/films/4/",
"http://swapi.dev/api/films/5/",
"http://swapi.dev/api/films/6/"
],
"created": "2014-12-09T13:50:49.641000Z",
"edited": "2014-12-21T20:48:04.175778Z",
"url": "http://swapi.dev/api/planets/1/"
}
```

## License (MIT)
Copyright (c) 2014-2023 [Peter Hellberg](https://c7.se)
> Permission is hereby granted, free of charge, to any person obtaining
> a copy of this software and associated documentation files (the "Software"),
> to deal in the Software without restriction, including without limitation
> the rights to use, copy, modify, merge, publish, distribute, sublicense,
> and/or sell copies of the Software, and to permit persons to whom the
> Software is furnished to do so, subject to the following conditions:
>
> The above copyright notice and this permission notice shall be included
> in all copies or substantial portions of the Software.
>
> THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
> EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
> OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
> IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
> DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
> TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
> OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.