The Authors resource allows you to manage author records in your application. Each author resource represents an author entity, which includes details such as the author's name, biography, and birth date.
The following fields are available for each author resource:
The Authors resource exposes various endpoints to manage author resources. Below are the available endpoints and their HTTP methods:
Method | Endpoint | Description |
---|---|---|
GET | /api/authors | Fetch all authors. |
GET | /api/authors/{id} | Fetch a specific author by ID. |
POST | /api/authors | Create a new author. |
PUT | /api/authors/{id} | Update an author's information. |
DELETE | /api/authors/{id} | Delete an author by ID. |
API requests may include parameters that influence the response. Parameters are categorized as path parameters, query parameters, or request bodies.
For creating or updating an author, the following fields are used in the request body:
Name | Type | Required | Description |
---|---|---|---|
name | string | Yes | The full name of the author. |
biography | string | No | A short biography of the author. |
birthDate | string | No | The birth date of the author (YYYY-MM-DD format). |
nationality | string | No | The nationality of the author. |
Below are examples for each type of request to the Authors API.
fetch('/api/authors')
.then(response => response.json())
.then(data => console.log(data))
.catch(error => console.error('Error:', error));
fetch('/api/authors/1')
.then(response => response.json())
.then(data => console.log(data))
.catch(error => console.error('Error:', error));
fetch('/api/authors', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({
name: 'Jane Austen',
biography: 'English novelist known for her six major novels...',
birthDate: '1775-12-16',
nationality: 'British'
})
})
.then(response => response.json())
.then(data => console.log(data))
.catch(error => console.error('Error:', error));
These examples illustrate the expected JSON responses for each endpoint.
[
{
"id": 1,
"name": "Jane Austen",
"biography": "English novelist known for her six major novels...",
"birthDate": "1775-12-16",
"nationality": "British"
},
{
"id": 2,
"name": "Mark Twain",
"biography": "American writer, humorist, and lecturer...",
"birthDate": "1835-11-30",
"nationality": "American"
}
]
{
"id": 1,
"name": "Jane Austen",
"biography": "English novelist known for her six major novels...",
"birthDate": "1775-12-16",
"nationality": "British"
}
{
"id": 3,
"name": "Charles Dickens",
"biography": "English writer and social critic...",
"birthDate": "1812-02-07",
"nationality": "British"
}