Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature one #48

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
217 changes: 169 additions & 48 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,49 +1,170 @@
# API Development and Documentation Final Project
# Trivia API Documentation

This documentation provides detailed information about the available API endpoints in the Trivia application. Each endpoint is described with its URL, request parameters, and expected response body.

## API Endpoints

### 1. GET `/categories`
**Description**: Fetches all categories.

**Request Parameters**: None

**Response Body**:
```json
{
"success": true,
"categories": {
"1": "Science",
"2": "Art"
// other categories
}
}
```
### 2. GET `/questions`
**Description**: Fetches all questions with pagination.

**Request Parameters**: page (optional): Page number for pagination (default: 1)

**Response Body**:
```json
{
"success": true,
"questions": [
{
"id": 1,
"question": "What is the capital of France?",
"answer": "Paris",
"category": "1",
"difficulty": 1
}
// other questions
],
"total_questions": 50
}
```
### 3. DELETE /questions/question_id
**Description**: Deletes a specific question.

**Request Parameters**: None

**Response Body**:
```json
{
"success": true,
"deleted": 1
}
```
### 4. POST /questions
**Description**: Adds a new question.

**Request Parameters**: None

**Request Body**:
```json
{
"question": "What is the largest planet?",
"answer": "Jupiter",
"category": "1",
"difficulty": 3
}
```

**Response Body**:
```json
{
"success": true
}
```
### 5. POST /questions/search
**Description**: Adds a new question.

**Request Parameters**: None

**Request Body**:
```json
{
"searchTerm": "planet"
}
```
**Response Body**:
```json
{
"success": true,
"questions": [
{
"id": 1,
"question": "What is the largest planet?",
"answer": "Jupiter",
"category": "1",
"difficulty": 3
}
// other matching questions
],
"total_questions": 1
}
```
### 6. GET /categories/category_id/questions
**Description**: Fetches questions for a specific category.

**Request Parameters**: None

**Response Body**:
```json
{
"success": true,
"questions": [
{
"id": 1,
"question": "What is the capital of France?",
"answer": "Paris",
"category": "1",
"difficulty": 1
}
// other questions in the category
],
"total_questions": 10,
"current_category": 1
}
```
### 7. POST /quizzes
**Description**: Fetches the next question for a quiz.

**Request Parameters**: None

**Request Body**:
```json
{
"previous_questions": [1, 2],
"quiz_category": {
"id": "1",
"type": "Science"
}
}
```
**Response Body**:
```json
{
"success": true,
"question": {
"id": 3,
"question": "What is the boiling point of water?",
"answer": "100°C",
"category": "1",
"difficulty": 1
}
}
```
### 8. ERROR HANDLING
**The API returns error responses in the following format**:
```json
{
"success": false,
"error": 404,
"message": "Resource not found"
}
```
**Error Codes**:
- 400: Bad request
- 404: Resource not found
- 422: Unprocessable entity

## Trivia App

Udacity is invested in creating bonding experiences for its employees and students. A bunch of team members got the idea to hold trivia on a regular basis and created a webpage to manage the trivia app and play the game, but their API experience is limited and still needs to be built out.

That's where you come in! Help them finish the trivia app so they can start holding trivia and seeing who's the most knowledgeable of the bunch. The application must:

1. Display questions - both all questions and by category. Questions should show the question, category and difficulty rating by default and can show/hide the answer.
2. Delete questions.
3. Add questions and require that they include question and answer text.
4. Search for questions based on a text query string.
5. Play the quiz game, randomizing either all questions or within a specific category.

Completing this trivia app will give you the ability to structure plan, implement, and test an API - skills essential for enabling your future applications to communicate with others.

## Starting and Submitting the Project

[Fork](https://help.github.com/en/articles/fork-a-repo) the project repository and [clone](https://help.github.com/en/articles/cloning-a-repository) your forked repository to your machine. Work on the project locally and make sure to push all your changes to the remote repository before submitting the link to your repository in the Classroom.

## About the Stack

We started the full stack application for you. It is designed with some key functional areas:

### Backend

The [backend](./backend/README.md) directory contains a partially completed Flask and SQLAlchemy server. You will work primarily in `__init__.py` to define your endpoints and can reference models.py for DB and SQLAlchemy setup. These are the files you'd want to edit in the backend:

1. `backend/flaskr/__init__.py`
2. `backend/test_flaskr.py`

> View the [Backend README](./backend/README.md) for more details.

### Frontend

The [frontend](./frontend/README.md) directory contains a complete React frontend to consume the data from the Flask server. If you have prior experience building a frontend application, you should feel free to edit the endpoints as you see fit for the backend you design. If you do not have prior experience building a frontend application, you should read through the frontend code before starting and make notes regarding:

1. What are the end points and HTTP methods the frontend is expecting to consume?
2. How are the requests from the frontend formatted? Are they expecting certain parameters or payloads?

Pay special attention to what data the frontend is expecting from each API response to help guide how you format your API. The places where you may change the frontend behavior, and where you should be looking for the above information, are marked with `TODO`. These are the files you'd want to edit in the frontend:

1. `frontend/src/components/QuestionView.js`
2. `frontend/src/components/FormView.js`
3. `frontend/src/components/QuizView.js`

By making notes ahead of time, you will practice the core skill of being able to read and understand code and will have a simple plan to follow to build out the endpoints of your backend API.

> View the [Frontend README](./frontend/README.md) for more details.
Loading