This project provides a simple API for managing flashcards, including creating, reviewing, and fetching flashcards. The API is built using the Hono framework and MongoDB for data storage.
-
Clone the repository:
git clone https://github.com/yourusername/flashcard-api.git cd flashcard-api
-
Install dependencies:
npm install
-
Set up your MongoDB connection in
src/db.ts
:const uri = "your_mongodb_connection_string";
-
Start the development server:
npm run dev
Once the server is running, you can interact with the API using tools like curl
, Postman
, or any HTTP client.
- URL:
/flashcards/due
- Method:
GET
- Description: Fetches all flashcards that are due for review.
- Response:
[ { "_id": "flashcard_id", "question": "What is the capital of France?", "answer": "Paris", "interval": 1, "repetitions": 0, "easeFactor": 2.5, "nextReview": "2023-10-01T00:00:00.000Z" } ]
- URL:
/flashcards/review
- Method:
POST
- Description: Reviews a flashcard and updates its scheduling parameters.
- Request Body:
{ "id": "flashcard_id", "userAnswer": "Paris" }
- Response:
{ "_id": "flashcard_id", "question": "What is the capital of France?", "answer": "Paris", "interval": 2, "repetitions": 1, "easeFactor": 2.6, "nextReview": "2023-10-02T00:00:00.000Z" }
- URL:
/flashcards
- Method:
GET
- Description: Fetches all flashcards.
- Response:
[ { "_id": "flashcard_id", "question": "What is the capital of France?", "answer": "Paris", "interval": 1, "repetitions": 0, "easeFactor": 2.5, "nextReview": "2023-10-01T00:00:00.000Z" } ]
- URL:
/flashcards
- Method:
POST
- Description: Creates a new flashcard.
- Request Body:
{ "question": "What is the capital of France?", "answer": "Paris" }
- Response:
{ "_id": "flashcard_id", "question": "What is the capital of France?", "answer": "Paris", "interval": 1, "repetitions": 0, "easeFactor": 2.5, "nextReview": "2023-10-01T00:00:00.000Z" }
-
URL:
/flashcards/bulk
-
Method:
POST
-
Description: Creates multiple flashcards in bulk.
-
Request Body:
{ "flashcards": [ { "question": "What is the capital of France?", "answer": "Paris" }, { "question": "What is 2 + 2?", "answer": "4" } ] }
-
Response:
[ { "_id": "flashcard_id_1", "question": "What is the capital of France?", "answer": "Paris", "interval": 1, "repetitions": 0, "easeFactor": 2.5, "nextReview": "2023-10-01T00:00:00.000Z" }, { "_id": "flashcard_id_2", "question": "What is 2 + 2?", "answer": "4", "interval": 1, "repetitions": 0, "easeFactor": 2.5, "nextReview": "2023-10-01T00:00:00.000Z" } ]
A flashcard object has the following structure:
interface Flashcard {
id: string;
question: string;
answer: string;
interval: number;
repetitions: number;
easeFactor: number;
nextReview: string;
}
- Fork the repository.
- Create a new branch (
git checkout -b feature-branch
). - Make your changes.
- Commit your changes (
git commit -m 'Add some feature'
). - Push to the branch (
git push origin feature-branch
). - Open a pull request.
This project is licensed under the MIT License - see the LICENSE file for details.
For any questions or feedback, please open an issue.