This API provides endpoints for searching and retrieving detailed information about yachts and ships. Built with Next.js, it serves as a middleware between client applications and the Ankor.io API, handling authentication, data enrichment, caching, and more.
- Authentication: JWT-based authentication system for secure API access
- Caching: In-memory caching to improve performance and reduce API calls
- Search Functionality: Advanced filtering options for yacht/ship search
- Data Enrichment: Enhances yacht data with operating areas, pricing, and region information
- Currency Conversion: Support for multiple currencies
- Error Handling: Robust error handling with informative messages
- CORS Support: Cross-Origin Resource Sharing for frontend integration
- Generates a JWT assertion for authentication with the Ankor.io API
- No request parameters required
- Exchanges JWT assertion for an access token
- No request parameters required
Search for yachts with various filter options.
Query Parameters:
limit(default: 50): Number of results to returnoffset(default: 0): Pagination offsetsort(default: "name"): Sort fieldorder(default: "asc"): Sort orderuri: Optional specific yacht URI for detailed informationmake: Filter by yacht manufacturername: Filter by vessel namelength_min/length_max: Filter by yacht lengthsleeps_min: Filter by minimum sleeping capacityyear_min: Filter by minimum build yearyachtType: Filter by yacht typeregion: Filter by geographic regionguests: Filter by guest capacitycheckIn/checkOut: Filter by availability datescurrency: Display price in specific currencypriceMin/priceMax: Filter by price range
Fetch detailed information for a specific yacht.
Query Parameters:
uri: Required - Unique identifier for the yacht
Fetch detailed information for a specific ship.
Query Parameters:
uri: Required - Unique identifier for the ship
Search for ships with various filter options.
Query Parameters:
- Similar to
/api/yachtbut tailored for ships
Generic search endpoint with more filter options.
Get exchange rates for currency conversion.
Query Parameters:
from(default: "USD"): Base currencyto: Target currency (optional)amount(default: 1): Amount to convert
The API uses a middleware pattern:
- Client makes request to Next.js API endpoints
- API authenticates with Ankor.io using JWT
- Requests are made to the Ankor.io API with the obtained token
- Results are cached, enriched, and formatted before returning to the client
- Error handling and retry mechanisms ensure reliable operation
The API implements multiple caching layers:
- Token cache: Stores authentication tokens to minimize auth requests
- Response cache: Stores API responses with a 5-minute TTL
- Yacht details cache: Stores detailed yacht information separately
The API handles various error scenarios:
- Authentication failures
- Rate limiting issues
- Timeouts with retry mechanisms
- Invalid parameters with descriptive error messages
Required environment variables:
BASE_URL: Base URL of your APINEXT_PUBLIC_BASE_ANKOR_API_URL: Ankor API base URLPRIVATE_KEY: Private key for JWT signingKEY_ID: Key ID for JWT headerNEXT_PUBLIC_COMPANY_URI: Company URI for authentication
- Node.js (v18+)
- npm or yarn
# Clone the repository
git clone https://your-repository.git
cd your-repository
# Install dependencies
npm install
# Set up environment variables
cp .env.example .env.local
# Edit .env.local with your credentials
# Run development server
npm run dev# Build for production
npm run build
# Start production server
npm start- Built with Next.js API routes
- Uses axios for HTTP requests
- Implements exponential backoff for API retries
- Handles concurrent requests with batching
- Processes a maximum of 20 yachts in detail to avoid timeouts
400: Invalid request parameters401: Authentication failed429: Rate limit exceeded500: Internal server error
Contributions are welcome! Please feel free to submit a Pull Request.
This project is licensed under the MIT License.