Building an Android App Discovery Site with AppBrain API and Swagger

Welcome to our engineering blog! In the upcoming series of short technical blog posts, we will be sharing our experiences about developing FreeAppy, an Android app discovery site.

It takes you step by step through the process how we developed this site. We hope that our posts will be informative and useful to other developers who are working on similar projects.

FreeAppy is a website that helps users discover the best free apps available on the Google Play Store. It is built with Astro, AppBrain API, and ChatGPT.

Getting the data about Android apps is the most important aspect of this app discovery website. Fortunately, the AppBrain API offers an easy-to-use way to get this data. Their API is described with the OpenAPI specification, this makes it possible to automatically generate an API client for it.

We are using the Astro web framework which is using TypeScript, therefore our API client needs to be generated in Typescript aswell.

A very easy to use tool for this is swagger-typescript-api.

This command creates a TypeScript API client for the AppBrain API:

pnpx swagger-typescript-api \
  -p https://api.appbrain.com/v2/swagger.json \
  --api-class-name AppBrainApi -n appbrainApi.ts

The generated client code is in appbrainApi.ts. The snippet below shows how to instantiate and setup the API client. The customFetch part is needed to handle error messages in case of an error.

const token = import.meta.env.API_KEY;

export const appbrainApi = new AppBrainApi({
  customFetch: (...params) => {
    const url = params[0].toString();
    return fetch(...params).then(async (response) => {
      if (!response.ok) {
        const text = await response.text();
        return new Response(JSON.stringify({ message: text }), {
          status: response.status,
          statusText: response.statusText,
        });
      } else {
        return response;
      }
    })}
});
appbrainApi.setSecurityData(token);

Fetch lists of apps using the browseApps method:

const response = await appbrainApi.info.browseApps({
  category: "GAMES",
  sort: 'HOT-DAY',
  limit: 20,
  offset: 0
});

To get started, we first need to obtain an API key from AppBrain. The signup is quite simple, once you have the key you can place it in your .env file to make it available to the web app via import.meta.env.API_KEY.

In conclusion, fetching data with the a Swagger/OpenAPI has been a straightforward process and it can be an excellent way to start building an Android app discovery site. In the next post we will look into setting up an Astro project and display the app information.

Thank you for reading and we look forward to sharing more of our experiences with you!

About

FreeAppy.com is an Android app discovery site. We try to offer a clean and simple mobile website to find fun apps and games.

More posts

  1. FreeAppy Launch!