Star Wars API

Star Wars API

Public API Docs: SWAPI

The Star Wars API (SWAPI) is a public API that provides data from the Star Wars universe, including information on characters, films, planets, and more.

Getting started

To start using the SWAPI, you’ll need to make requests to its URL endpoints. The base URL for SWAPI is From here, you can access all the available resources by adding the appropriate endpoint to the URL.

For example, to get information on the first Star Wars film, A New Hope, you would make a GET request to

Example code in JavaScript

To make requests to the SWAPI in JavaScript, you can use tools like the fetch API or libraries like axios. Here are some example snippets of code that illustrate how to get data from the SWAPI:

Using the fetch API

const url = '';

    .then((response) => response.json())
    .then((data) => console.log(data));

Using axios

const axios = require('axios');

const url = '';

    .then((response) => console.log(
    .catch((error) => console.log(error));


SWAPI uses pagination to limit the amount of data returned in a single request. You can specify the page number by adding a page parameter to the URL.

For example, to get the second page of Star Wars characters, you would make a GET request to

Here’s some example code that shows how to get all data by paginating through the results:

const url = '';
let allData = [];

function fetchData(url) {
        .then((response) => {
            allData = [...allData,];
            if ( {
            } else {
        .catch((error) => console.log(error));



In this blog post, we’ve covered the basics of using the SWAPI, including how to make requests to its API endpoints in JavaScript, as well as how to handle pagination to get all available data.

With this knowledge, you can start exploring all the amazing data available in the Star Wars universe through the SWAPI.