Repository navigation
Releases
Releases · khairulas/restful-api-integration
RESTful API Integration v1.0
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:
- Google Books API: Fetch additional details about books such as authors, descriptions, and links to view them on Google Books.
- 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
-
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.
-
Service Consumer:
- A PHP-based front-end to interact with the local API.
- Features:
- View, create, update, and delete book resources.
-
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.
-
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
- A local PHP development environment (e.g., XAMPP, WAMP, or LAMP).
- Composer installed (optional but recommended).
- API keys for:
- Google Books API: Google Books API Documentation.
- NYT Book Review API: NYT Developer Portal.
Steps
-
Clone the repository:
git clone https://github.com/your-repo-name.git cd your-repo-name -
Set up the database:
- Import the provided
database.sqlfile into your MySQL database. - Update database credentials in the
restful_api_with_pdo.phpfile.
- Import the provided
-
Configure API keys:
- Create an
.envfile or update the code with your API keys. - Example
.envfile:GOOGLE_API_KEY=your-google-api-key NYT_API_KEY=your-nyt-api-key
- Create an
-
Run the application:
- Start your PHP server:
php -S localhost:8000
- Access the application at
http://localhost:8000.
- Start your PHP server:
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
-
View All Resources:
- Access the home page (
index.php) to see all books in the local database.
- Access the home page (
-
Create a New Resource:
- Use the "Create Resource" form to add a new book to the database.
-
View a Book:
- Click "View" to see book details and external data fetched from the Google Books API and NYT Book Review API.
-
Update a Book:
- Click "Update" to modify a book's information.
-
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
- Add search and filtering options to the front-end.
- Implement caching for external API responses to reduce dependency on live data.
- Improve error handling and logging.
- Add support for pagination for large datasets.
License
This project is licensed under the MIT License. See the LICENSE file for details.