The country flag endpoint provides access to flag icons for all countries. This is useful for displaying user locations, regional settings, and country-specific information in your application.
Get country flag
Retrieve a country flag icon by its ISO 3166-1 country code.
import { Client, Avatars, Flag } from "appwrite";
const client = new Client()
.setEndpoint('https://<REGION>.cloud.appwrite.io/v1')
.setProject('<PROJECT_ID>');
const avatars = new Avatars(client);
const result = avatars.getFlag({
code: Flag.UnitedStates,
width: 100,
height: 100
});
console.log(result); // Resource URL
Parameters
The getFlag method accepts the following parameters:
| Parameter | Type | Description |
code | string | |
width | integer | The width of the output image in pixels. Accepts values between 0-2000. |
height | integer | The height of the output image in pixels. Accepts values between 0-2000. |
Country codes
Use ISO 3166-1 alpha-2 country codes to specify the country. These are two-letter codes that uniquely identify countries.
import { Flag } from "appwrite";
// United States
const usFlag = avatars.getFlag({
code: Flag.UnitedStates,
width: 100,
height: 100
});
// United Kingdom
const ukFlag = avatars.getFlag({
code: Flag.UnitedKingdom,
width: 100,
height: 100
});
// France
const frFlag = avatars.getFlag({
code: Flag.France,
width: 100,
height: 100
});
Use cases
Country flags are commonly used for:
- Session information: Display user session location visually alongside flag icons. Country codes from session data match perfectly with flags codes, allowing you to create cohesive visual session displays
- User profiles: Display user country or location in profile pages
- Regional settings: Show available regions or languages by country
- Analytics dashboards: Visualize geographic data and user distribution
- Localization: Indicate content availability or regional restrictions
- Shipping information: Display origin and destination countries in shipping interfaces