This project serves as a demo showcase for how easy it is to integrate and use a Fern-generated TypeScript SDK in a modern React application. It highlights the developer experience benefits of Fern's SDK generation:
- Type Safety: Full TypeScript support out of the box
- Simple API: Clean, intuitive method calls
- Zero Configuration: No complex setup required
- Excellent DX: IntelliSense and autocomplete support
The Fern-generated SDK is installed as a standard npm package:
npm install disney-public-sdk
The SDK integration is remarkably simple and can be found in `app/page.tsx`:
import { DisneyOpensourceClient } from "disney-public-sdk"
const client = new DisneyOpensourceClient()
const shuffleAndDraw = async () => {
try {
// Fetch all characters from the Disney API
const allCharacters = await client.getAllCharacters()
// Select a random character
const randomIndex = Math.floor(Math.random() * allCharacters.data.length)
const randomCharacter = allCharacters.data[randomIndex]
setCharacter(randomCharacter)
} catch (err) {
console.error("Error fetching character:", err)
setError("Failed to fetch character. Please try again.")
}
}
- No Configuration Required: The client works immediately without any setup
- Type Safety: Full TypeScript interfaces for all API responses
- Error Handling: Built-in error handling with proper TypeScript types
- IntelliSense Support: Full autocomplete for methods and response properties
- Promise-Based: Modern async/await support
The SDK returns well-typed character objects with the following structure:
interface DisneyCharacter {
_id: number
name: string
imageUrl?: string
films?: string[]
shortFilms?: string[]
tvShows?: string[]
videoGames?: string[]
parkAttractions?: string[]
allies?: string[]
enemies?: string[]
sourceUrl?: string
}
The Fern SDK is used in the following locations:
- Line 8: SDK import statement
- Line 30: Client initialization
- Line 39: `client.getAllCharacters()` method call
- Simple Import: Single import statement for the entire SDK
- Zero Config: No environment variables or configuration needed
- Type Safety: Full TypeScript support with proper interfaces
- Error Handling: Graceful error handling with try/catch
- Async Operations: Modern Promise-based API calls
This project showcases several key advantages of Fern-generated SDKs:
- Developer Experience: From zero to API calls in 3 lines of code
- Type Safety: No manual type definitions needed
- Consistency: Standardized patterns across all API methods
- Maintainability: SDK updates automatically when API changes
- Documentation: Self-documenting code through TypeScript types
- Simplicity: Complex API interactions made simple
Built with ❤️ to showcase the power of Fern-generated TypeScript SDKs