#fortnite #api #tokio

fortnite-api

A library for interacting with the Fortnite API

4 releases

0.1.3 May 25, 2024
0.1.2 Feb 10, 2024
0.1.1 Feb 6, 2024
0.1.0 Feb 6, 2024

#1 in #fortnite

Download history 15/week @ 2024-08-15 5/week @ 2024-08-22 5/week @ 2024-08-29 13/week @ 2024-09-19 10/week @ 2024-09-26 6/week @ 2024-10-03 2/week @ 2024-10-10

258 downloads per month

MIT license

45KB
877 lines

Fortnite API

This crate is a wrapper for the Fortnite API.

Usage

#[tokio::main]
async fn main() {
    let http_client = reqwest::Client::new();

    let result = fortnite_api::get_news_v2(&http_client, None).await;
    println!("Result: {:#?}", result);
    assert!(result.is_ok());
}

Endpoints

Endpoint Function Result Type
AES V2 get_aes_keys_v2 AesV2
Banners V1 get_banners_v1 BannersV1
Banners Colors V1 get_banners_colors_v1 BannersColorsV1
Cosmetics V2 get_cosmetics_v2 CosmeticsV2
Cosmetics New V2 get_cosmetics_new_v2 CosmeticsNewV2
Cosmetic By ID V2 get_cosmetic_by_id_v2 CosmeticV2
Creator Code V2 get_creatorcode_v2 CreatorCodeV2
Map V1 get_map_v1 MapV1
News V2 get_news_v2 NewsV2
News Gamemode V2 get_news_br_v2 get_news_stw_v2 get_news_creative_v2 News
Playlists V1 get_playlists_v1 PlaylistsV1
Playlists By ID V1 get_playlist_by_id_v1 PlaylistV1
Shop BR V2 get_shop_br_v2 get_shop_combined_v2 ShopV2
Stats V2 get_stats_v2 get_stats_by_account_id_v2 StatsV2

Get the current AES keys.

Parameters

  • http_client: The reqwest client.
  • key_format: The format of the AES keys. Can be None, Some(AesKeyFormat::Hex), or Some(AesKeyFormat::Base64).

Returns

The current AES keys.

Example

use fortnite_api::response_types::aes::AesKeyFormat;

#[tokio::main]
async fn main() {
    let http_client = reqwest::Client::new();

    let result = fortnite_api::get_aes_keys_v2(&http_client, Some(AesKeyFormat::Hex)).await;
    println!("Result: {:#?}", result);
    assert!(result.is_ok());
}

Get the banners.

Parameters

  • http_client: The reqwest client.
  • language: The language of the banners. Can be None or a language code.

Returns

The banners.

Example

#[tokio::main]
async fn main() {
    let http_client = reqwest::Client::new();

    let result = fortnite_api::get_banners_v1(&http_client, None).await;
    println!("Result: {:#?}", result);
    assert!(result.is_ok());
}

Get the banner colors.

Parameters

  • http_client: The reqwest client.

Returns

The banner colors.

Example

#[tokio::main]
async fn main() {
    let http_client = reqwest::Client::new();

    let result = fortnite_api::get_banners_colors_v1(&http_client).await;
    println!("Result: {:#?}", result);
    assert!(result.is_ok());
}

Get the cosmetics.

Parameters

  • http_client: The reqwest client.
  • language: The language of the cosmetics. Can be None or a language code.

Returns

The cosmetics.

Example

#[tokio::main]
async fn main() {
    let http_client = reqwest::Client::new();

    let result = fortnite_api::get_cosmetics_v2(&http_client, None).await;
    assert!(result.is_ok());
}

Get the new cosmetics.

Parameters

  • http_client: The reqwest client.
  • language: The language of the cosmetics. Can be None or a language code.

Returns

The new cosmetics.

Example

#[tokio::main]
async fn main() {
    let http_client = reqwest::Client::new();

    let result = fortnite_api::get_cosmetics_new_v2(&http_client, None).await;
    assert!(result.is_ok());
}

Get the cosmetic by ID.

Parameters

  • http_client: The reqwest client.
  • cosmetic_id: The ID of the cosmetic.
  • language: The language of the cosmetic. Can be None or a language code.

Returns

The cosmetic by ID.

Example

#[tokio::main]
async fn main() {
    let http_client = reqwest::Client::new();

    let result = fortnite_api::get_cosmetics_new_v2(&http_client, None).await;
    assert!(result.is_ok());

    let cosmetic_id = result.unwrap().items.first().unwrap().id.clone();
    let result = fortnite_api::get_cosmetic_by_id_v2(&http_client, &cosmetic_id, None).await;
    println!("Result: {:#?}", result);
    assert!(result.is_ok());
}

Get the creator code.

Parameters

  • http_client: The reqwest client.
  • name: The name of the creator code.

Returns

The creator code.

Example

#[tokio::main]
async fn main() {
    let http_client = reqwest::Client::new();

    let result = fortnite_api::get_creatorcode_v2(&http_client, "trymacs").await;
    println!("Result: {:#?}", result);
    assert!(result.is_ok());
}

Get the map.

Parameters

  • http_client: The reqwest client.
  • language: The language of the map. Can be None or a language code.

Returns

The map.

Example

#[tokio::main]
async fn main() {
    let http_client = reqwest::Client::new();

    let result = fortnite_api::get_map_v1(&http_client, None).await;
    println!("Result: {:#?}", result);
    assert!(result.is_ok());
}

Get the news.

Parameters

  • http_client: The reqwest client.
  • language: The language of the news. Can be None or a language code.

Returns

The news.

Example

#[tokio::main]
async fn main() {
    let http_client = reqwest::Client::new();

    let result = fortnite_api::get_news_v2(&http_client, None).await;
    println!("Result: {:#?}", result);
}

Get the battle royale news.

Parameters

  • http_client: The reqwest client.
  • language: The language of the news. Can be None or a language code.

Returns

The battle royale news.

Example

#[tokio::main]
async fn main() {
    let http_client = reqwest::Client::new();

    let result = fortnite_api::get_news_br_v2(&http_client, None).await;
    println!("Result: {:#?}", result);
}

Get the save the world news.

Parameters

  • http_client: The reqwest client.
  • language: The language of the news. Can be None or a language code.

Returns

The save the world news.

Example

#[tokio::main]
async fn main() {
    let http_client = reqwest::Client::new();

    let result = fortnite_api::get_news_stw_v2(&http_client, None).await;
    println!("Result: {:#?}", result);
}

Get the creative news.

Parameters

  • http_client: The reqwest client.
  • language: The language of the news. Can be None or a language code.

Returns

The creative news.

Example

#[tokio::main]
async fn main() {
    let http_client = reqwest::Client::new();

    let result = fortnite_api::get_news_creative_v2(&http_client, None).await;
    println!("Result: {:#?}", result);
}

Get the playlists.

Parameters

  • http_client: The reqwest client.
  • language: The language of the playlists. Can be None or a language code.

Returns

The playlists.

Example

#[tokio::main]
async fn main() {
    let http_client = reqwest::Client::new();

    let result = fortnite_api::get_playlists_v1(&http_client, None).await;
    println!("Result: {:#?}", result);
    assert!(result.is_ok());
}

Get the playlist by ID.

Parameters

  • http_client: The reqwest client.
  • language: The language of the playlists. Can be None or a language code.

Returns

The playlist by ID.

Example

#[tokio::main]
async fn main() {
    let http_client = reqwest::Client::new();

    let result = fortnite_api::get_playlists_v1(&http_client, None).await;
    println!("Result: {:#?}", result);
    assert!(result.is_ok());

    let playlist_id = result.unwrap().first().unwrap().id.clone();
    let result = fortnite_api::get_playlist_by_id_v1(&http_client, &playlist_id, None).await;
    println!("Result: {:#?}", result);
}

Get the battle royale shop.

Parameters

  • http_client: The reqwest client.
  • language: The language of the shop. Can be None or a language code.

Returns

The battle royale shop.

Example

#[tokio::main]
async fn main() {
    let http_client = reqwest::Client::new();

    let result = fortnite_api::get_shop_br_v2(&http_client, None).await;
    println!("Result: {:#?}", result);
    assert!(result.is_ok());
}

Get the combined shop.

Parameters

  • http_client: The reqwest client.
  • language: The language of the shop. Can be None or a language code.

Returns

The combined shop.

Example

#[tokio::main]
async fn main() {
    let http_client = reqwest::Client::new();

    let result = fortnite_api::get_shop_combined_v2(&http_client, None).await;
    println!("Result: {:#?}", result);
    assert!(result.is_ok());
}

Get the player stats.

Parameters

  • http_client: The reqwest client.
  • api_key: Your Fortnite API key.
  • name: The name of the player.
  • account_type: The account type of the player. Can be None or StatsAccountType.
  • time_window: The time window of the stats. Can be None or StatsTimeWindow.
  • image: The image of the stats. Can be None or StatsImage.
  • language: The language of the shop. Can be None or a language code.

Returns

The player stats.

Example

use fortnite_api::response_types::stats::{StatsAccountType, StatsImage, StatsTimeWindow};

#[tokio::main]
async fn main() {
    dotenv::dotenv().ok();
    let http_client = reqwest::Client::new();
    let api_key = std::env::var("FORTNITE_API_KEY")
        .expect("Please set the FORTNITE_API_KEY environment variable");

    let result =
        fortnite_api::get_stats_v2(&http_client, api_key.clone(), "Test", None, None, None).await;
    println!("Result: {:#?}", result);
    assert!(result.is_ok());
}

Get the player stats by account ID.

Parameters

  • http_client: The reqwest client.
  • api_key: Your Fortnite API key.
  • account_id: The account ID of the player.
  • time_window: The time window of the stats. Can be None or StatsTimeWindow.
  • image: The image of the stats. Can be None or StatsImage.

Returns

The player stats.

Example

use fortnite_api::response_types::stats::{StatsAccountType, StatsImage, StatsTimeWindow};

#[tokio::main]
async fn main() {
    dotenv::dotenv().ok();
    let http_client = reqwest::Client::new();
    let api_key = std::env::var("FORTNITE_API_KEY")
        .expect("Please set the FORTNITE_API_KEY environment variable");

    let result = fortnite_api::get_stats_by_account_id_v2(
        &http_client,
        api_key.clone(),
        "3f20d6f579db4e7ba71d80fc18576db2",
        None,
        None,
    )
    .await;
    println!("Result: {:#?}", result);
    assert!(result.is_ok());
}

Dependencies

~5–16MB
~215K SLoC