### Wordle API Request Example (JSON) Source: https://github.com/petergeorgas/wordle-api/blob/main/README.md Demonstrates the JSON structure for sending a guess to the Wordle API. The request body should contain a 'guess' key with the user's attempted word. ```json { "guess":"words" } ``` -------------------------------- ### Wordle API Response Example - Correct Guess (JSON) Source: https://github.com/petergeorgas/wordle-api/blob/main/README.md Illustrates the JSON response from the Wordle API when a guess is correct. It includes the 'guess' and a 'was_correct' boolean set to true. ```json { "guess": "cross", "was_correct": true } ``` -------------------------------- ### Wordle API Response Example - Incorrect Guess (JSON) Source: https://github.com/petergeorgas/wordle-api/blob/main/README.md Shows the JSON response from the Wordle API for an incorrect guess. It includes the 'guess', 'was_correct' set to false, and detailed 'character_info' for each letter. ```json { "guess": "beans", "was_correct": false, "character_info": [ { "char": "b", "scoring": { "in_word": false, "correct_idx": false } }, { "char": "e", "scoring": { "in_word": false, "correct_idx": false } }, { "char": "a", "scoring": { "in_word": false, "correct_idx": false } }, { "char": "n", "scoring": { "in_word": false, "correct_idx": false } }, { "char": "s", "scoring": { "in_word": true, "correct_idx": true } } ] } ``` -------------------------------- ### Submit Word Guess to Wordle API (Bash) Source: https://context7.com/petergeorgas/wordle-api/llms.txt Demonstrates how to submit a 5-letter word guess to the Wordle API using curl. It shows example requests for incorrect and correct guesses, as well as error responses for invalid input like wrong word length or unsupported HTTP methods. ```bash # Submit a guess (incorrect example) curl -X POST https://wordle-api.vercel.app/api/wordle \ -H "Content-Type: application/json" \ -d '{"guess": "beans"}' # Response for incorrect guess: { "guess": "beans", "was_correct": false, "character_info": [ { "char": "b", "scoring": { "in_word": false, "correct_idx": false } }, { "char": "e", "scoring": { "in_word": false, "correct_idx": false } }, { "char": "a", "scoring": { "in_word": false, "correct_idx": false } }, { "char": "n", "scoring": { "in_word": false, "correct_idx": false } }, { "char": "s", "scoring": { "in_word": true, "correct_idx": true } } ] } # Response for correct guess: { "guess": "cross", "was_correct": true } # Error response for invalid word length: curl -X POST https://wordle-api.vercel.app/api/wordle \ -H "Content-Type: application/json" \ -d '{"guess": "hi"}' # Response: { "error": "Only 5 character words currently supported." } # Error response for wrong HTTP method: curl https://wordle-api.vercel.app/api/wordle # Response: { "error": "GET unsupported." } ``` -------------------------------- ### Get Daily Word of the Day (TypeScript) Source: https://context7.com/petergeorgas/wordle-api/llms.txt Illustrates how to retrieve the current day's Wordle word using the `getWordOfTheDay` function. This function ensures that all users receive the same word on a given day by using a date-based seed for pseudorandom selection. The results are cached for efficiency. ```typescript import { getWordOfTheDay } from "./word-util/util"; // Get today's word (same result for all calls on the same day) const todayWord = getWordOfTheDay(); console.log(todayWord); // e.g., "cross" // The word changes daily based on date seed // Day 8000 since 2000-01-01 will always return the same word ``` -------------------------------- ### Check Character Presence in Word (TypeScript) Source: https://context7.com/petergeorgas/wordle-api/llms.txt Provides an example of using the `isCharInWord` utility function. This function checks if a specific character exists within a given word, returning `true` if found and `false` otherwise. It's a core component for determining the 'in_word' status in the API's guess evaluation. ```typescript import { isCharInWord } from "./word-util/util"; // Check if character is present in word isCharInWord("a", "apple"); // true isCharInWord("z", "apple"); // false isCharInWord("p", "apple"); // true (even though 'p' appears twice) ``` -------------------------------- ### Calculate Days Since Epoch (TypeScript) Source: https://context7.com/petergeorgas/wordle-api/llms.txt Demonstrates the usage of the `getDayOfYear` function, which calculates the number of days elapsed since January 1, 2000. This value serves as the seed for the pseudorandom number generator used to select the daily Wordle word, ensuring consistency. ```typescript import { getDayOfYear } from "./word-util/util"; // Get day difference from 2000-01-01 const today = new Date(); const daysSince2000 = getDayOfYear(today); console.log(daysSince2000); // e.g., 8890 (depending on current date) // This value seeds the random number generator for word selection ``` -------------------------------- ### Utility Functions Source: https://context7.com/petergeorgas/wordle-api/llms.txt Internal utility functions used by the Wordle Serverless API to determine the daily word and validate guesses. These include `getWordOfTheDay`, `isCharInWord`, and `getDayOfYear`. ```APIDOC ## Utility Functions ### getWordOfTheDay() #### Description Returns the pseudorandomly-selected word of the day. The word is determined by seeding a random number generator with the number of days since January 1, 2000, ensuring consistent results across all API calls on the same day. Results are cached for performance. #### Usage Example (TypeScript) ```typescript import { getWordOfTheDay } from "./word-util/util"; // Get today's word (same result for all calls on the same day) const todayWord = getWordOfTheDay(); console.log(todayWord); // e.g., "cross" ``` ### isCharInWord(guess, answer) #### Description Utility function that checks if a character exists anywhere within a word. Used internally by the API to determine the `in_word` scoring field. #### Usage Example (TypeScript) ```typescript import { isCharInWord } from "./word-util/util"; // Check if character is present in word isCharInWord("a", "apple"); // true isCharInWord("z", "apple"); // false isCharInWord("p", "apple"); // true ``` ### getDayOfYear(date) #### Description Calculates the number of days between a given date and January 1, 2000. This value is used as the seed for pseudorandom word selection, ensuring reproducible daily words. #### Usage Example (TypeScript) ```typescript import { getDayOfYear } from "./word-util/util"; // Get day difference from 2000-01-01 const today = new Date(); const daysSince2000 = getDayOfYear(today); console.log(daysSince2000); // e.g., 8890 (depending on current date) ``` ``` -------------------------------- ### POST /api/wordle - Submit Word Guess Source: https://context7.com/petergeorgas/wordle-api/llms.txt Submits a 5-letter word guess to the API for validation against the daily word. Returns detailed feedback for each character, indicating if it's in the correct position, present but misplaced, or not in the word at all. Handles incorrect guesses, correct guesses, and errors for invalid input. ```APIDOC ## POST /api/wordle ### Description Validates a 5-letter word guess against the daily word and returns character-by-character scoring. Each character is evaluated for presence in the word (`in_word`) and correct position (`correct_idx`). Returns a simplified response for correct guesses. ### Method POST ### Endpoint /api/wordle ### Parameters #### Request Body - **guess** (string) - Required - The 5-letter word guess. ### Request Example ```json { "guess": "beans" } ``` ### Response #### Success Response (200) - **guess** (string) - The submitted guess. - **was_correct** (boolean) - True if the guess was the correct word, false otherwise. - **character_info** (array) - An array of objects, each containing: - **char** (string) - The character from the guess. - **scoring** (object) - An object with: - **in_word** (boolean) - True if the character is present in the daily word. - **correct_idx** (boolean) - True if the character is in the correct position. #### Success Response Example (Incorrect Guess) ```json { "guess": "beans", "was_correct": false, "character_info": [ { "char": "b", "scoring": { "in_word": false, "correct_idx": false } }, { "char": "e", "scoring": { "in_word": false, "correct_idx": false } }, { "char": "a", "scoring": { "in_word": false, "correct_idx": false } }, { "char": "n", "scoring": { "in_word": false, "correct_idx": false } }, { "char": "s", "scoring": { "in_word": true, "correct_idx": true } } ] } ``` #### Success Response Example (Correct Guess) ```json { "guess": "cross", "was_correct": true } ``` #### Error Response (400) - **error** (string) - Description of the error (e.g., "Only 5 character words currently supported."). #### Error Response Example (Invalid Length) ```json { "error": "Only 5 character words currently supported." } ``` #### Error Response (405) - **error** (string) - Description of the error (e.g., "GET unsupported."). #### Error Response Example (Wrong Method) ```json { "error": "GET unsupported." } ``` ``` -------------------------------- ### POST /api/wordle Source: https://github.com/petergeorgas/wordle-api/blob/main/README.md Submit a guess to the Wordle API to check its correctness against the daily word. This endpoint is designed to be used in Wordle clone applications to keep the answer secure on the server. ```APIDOC ## POST /api/wordle ### Description Submits a guessed word to the Wordle API to determine if it is the correct answer for the day. It provides feedback on the guess and detailed character analysis for incorrect guesses. ### Method POST ### Endpoint `https://wordle-api.vercel.app/api/wordle` ### Parameters #### Request Body - **guess** (string) - Required - The 5-letter word being guessed. ### Request Example ```json { "guess": "words" } ``` ### Response #### Success Response (200) - **guess** (string) - The word that was guessed. - **was_correct** (boolean) - Indicates if the guess was the correct answer. #### Incorrect Guess Response (200) - **guess** (string) - The word that was guessed. - **was_correct** (boolean) - Always `false` for an incorrect guess. - **character_info** (array) - An array of objects, each detailing a character in the guess. - **char** (string) - The character from the guess. - **scoring** (object) - Scoring information for the character. - **in_word** (boolean) - True if the character is present in the answer word, false otherwise. - **correct_idx** (boolean) - True if the character is in the correct position, false otherwise. #### Response Example (Correct Guess) ```json { "guess": "cross", "was_correct": true } ``` #### Response Example (Incorrect Guess) ```json { "guess": "beans", "was_correct": false, "character_info": [ { "char": "b", "scoring": { "in_word": false, "correct_idx": false } }, { "char": "e", "scoring": { "in_word": false, "correct_idx": false } }, { "char": "a", "scoring": { "in_word": false, "correct_idx": false } }, { "char": "n", "scoring": { "in_word": false, "correct_idx": false } }, { "char": "s", "scoring": { "in_word": true, "correct_idx": true } } ] } ``` ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.