Macronutrient API
This is a sample macronutrient calculator built with Github Codespaces, ChatGPT, Claude AI, and v0 by Vercel. It also uses zod for query validation.
Authentication
There's no authentication needed for this API, but usage will be limited by NextJS rate limits for the hobby plan.
Endpoints
GET /api/macros
Parameters (Query Strings)
Parameter | Type | Description | Required |
---|---|---|---|
age | number (integer) | Your age in years. | Yes |
height | number (float) | Your height in inches. | Yes |
weight | number (float) | Your weight in pounds. | Yes |
gender | string | Your gender, either "male" or "female". | Yes |
activityLevel | string | Your activity level, one of: "sedentary", "light", "moderate", "active", "extra". | Yes |
Example Request
GET /api/macros?age=30&height=70&weight=175&gender=male&activityLevel=moderate
Example Response
{ "message": { "bmi": 25.1096073620719, "calories": 2728, "protein": 175, "fats": 91, "carbs": 303 } }
Error Response
{ "error": [ "age: Expected string, received null", "height: Height must be a number", "weight: Expected string, received null", "gender: Gender must be "male" or "female"", "activityLevel: Activity level must be one of sedentary, light, moderate, active, extra" ] }