Bookshop API

Authors

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:

Endpoints and Methods

The Authors resource exposes various endpoints to manage author resources. Below are the available endpoints and their HTTP methods:

Endpoints Overview

MethodEndpointDescription
GET/api/authorsFetch all authors.
GET/api/authors/{id}Fetch a specific author by ID.
POST/api/authorsCreate a new author.
PUT/api/authors/{id}Update an author's information.
DELETE/api/authors/{id}Delete an author by ID.

Parameters

API requests may include parameters that influence the response. Parameters are categorized as path parameters, query parameters, or request bodies.

Path Parameters

Request Body Parameters

For creating or updating an author, the following fields are used in the request body:

NameTypeRequiredDescription
namestringYesThe full name of the author.
biographystringNoA short biography of the author.
birthDatestringNoThe birth date of the author (YYYY-MM-DD format).
nationalitystringNoThe nationality of the author.

Request Example

Below are examples for each type of request to the Authors API.

Get All Authors

fetch('/api/authors')
.then(response => response.json())
.then(data => console.log(data))
.catch(error => console.error('Error:', error));

Get Author by ID

fetch('/api/authors/1')
.then(response => response.json())
.then(data => console.log(data))
.catch(error => console.error('Error:', error));

Create a New Author

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));

Response

These examples illustrate the expected JSON responses for each endpoint.

Get All Authors

[
  {
      "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"
  }
]

Get Author by ID

{
  "id": 1,
  "name": "Jane Austen",
  "biography": "English novelist known for her six major novels...",
  "birthDate": "1775-12-16",
  "nationality": "British"
}

Create Author

{
  "id": 3,
  "name": "Charles Dickens",
  "biography": "English writer and social critic...",
  "birthDate": "1812-02-07",
  "nationality": "British"
}