Skip to content

RESTful API Integration v1.0

Latest

Choose a tag to compare

@khairulas khairulas released this 07 Jan 02:41
· 4 commits to main since this release
54f2ac6

RESTful API Integration with Google Books and NYT Book Review APIs

Overview

This project demonstrates the integration of a local RESTful API with two external APIs:

  1. Google Books API: Fetch additional details about books such as authors, descriptions, and links to view them on Google Books.
  2. New York Times Book Review API: Retrieve book reviews and summaries from the NYT Books API.

This project is designed as an educational example for a System Integration course to showcase how to use RESTful APIs effectively in real-world scenarios.


Features

  1. Local RESTful API:

    • A PHP-based API built with PDO for managing book resources (CRUD operations).
    • Endpoints:
      • GET /resources: Fetch all resources.
      • GET /resources/{id}: Fetch a single resource by ID.
      • POST /resources: Create a new resource.
      • PUT /resources/{id}: Update a resource by ID.
      • DELETE /resources/{id}: Delete a resource by ID.
  2. Service Consumer:

    • A PHP-based front-end to interact with the local API.
    • Features:
      • View, create, update, and delete book resources.
  3. Google Books API Integration:

    • Fetch additional book details based on the book title.
    • Display book title, authors, description, and a link to the book on Google Books.
  4. NYT Book Review API Integration:

    • Fetch book reviews based on the book title.
    • Display the book title, author, summary, and a link to the full review.

Installation

Prerequisites

  1. A local PHP development environment (e.g., XAMPP, WAMP, or LAMP).
  2. Composer installed (optional but recommended).
  3. API keys for:

Steps

  1. Clone the repository:

    git clone https://github.com/your-repo-name.git
    cd your-repo-name
  2. Set up the database:

    • Import the provided database.sql file into your MySQL database.
    • Update database credentials in the restful_api_with_pdo.php file.
  3. Configure API keys:

    • Create an .env file or update the code with your API keys.
    • Example .env file:
      GOOGLE_API_KEY=your-google-api-key
      NYT_API_KEY=your-nyt-api-key
  4. Run the application:

    • Start your PHP server:
      php -S localhost:8000
    • Access the application at http://localhost:8000.

File Structure

.
├── database.sql              # SQL script for setting up the database
├── restful_api_with_pdo.php  # Local RESTful API
├── index.php                 # Main entry point for the front-end
├── resource_view.php         # View a single resource and integrate with external APIs
├── update.php                # Update a resource
├── delete.php                # Confirm deletion of a resource
├── process.php               # Handles create, update, delete requests
├── README.md                 # Project documentation

Usage

  1. View All Resources:

    • Access the home page (index.php) to see all books in the local database.
  2. Create a New Resource:

    • Use the "Create Resource" form to add a new book to the database.
  3. View a Book:

    • Click "View" to see book details and external data fetched from the Google Books API and NYT Book Review API.
  4. Update a Book:

    • Click "Update" to modify a book's information.
  5. Delete a Book:

    • Click "Delete" to remove a book, with a confirmation step.

API Integration Details

Google Books API

  • Endpoint: https://www.googleapis.com/books/v1/volumes?q={query}
  • Authentication: Requires an API key.
  • Usage:
    • Queries are made using the book title.
    • Example query: https://www.googleapis.com/books/v1/volumes?q=Becoming&key=YOUR_GOOGLE_API_KEY.

NYT Book Review API

  • Endpoint: https://api.nytimes.com/svc/books/v3/reviews.json?title={title}
  • Authentication: Requires an API key.
  • Usage:
    • Queries are made using the book title.
    • Example query: https://api.nytimes.com/svc/books/v3/reviews.json?title=Becoming&api-key=YOUR_NYT_API_KEY.

Future Enhancements

  1. Add search and filtering options to the front-end.
  2. Implement caching for external API responses to reduce dependency on live data.
  3. Improve error handling and logging.
  4. Add support for pagination for large datasets.

License

This project is licensed under the MIT License. See the LICENSE file for details.


Acknowledgements

  1. Google Books API
  2. NYT Book Review API