Click Below to Get the Code

Browse, clone, and build from real-world templates powered by Harper.
Tutorial
GitHub Logo

Building a Library Management System with Harper

Learn how to create a full Library Management System using Harper. Define GraphQL schemas, implement resource classes, and build APIs without boilerplate code.
Tutorial

Building a Library Management System with Harper

By
Nenne Nwodo
May 12, 2025
By
Nenne Nwodo
May 12, 2025
May 12, 2025
Learn how to create a full Library Management System using Harper. Define GraphQL schemas, implement resource classes, and build APIs without boilerplate code.
Nenne Nwodo
Developer Relations

In this article, we'll develop a complete Library Management System using Harper, demonstrating how this modern platform makes building robust APIs straightforward and efficient.

Understanding Our Library Management System

Before diving into the code, let's understand what our system will accomplish. We're building a Library Management System with two primary components:

  • Book Management - Creating, retrieving, updating, and deleting books in our library catalog
  • Member Management - Managing library patrons with similar CRUD (Create, Read, Update, Delete) operations

Each book in our system will have properties like title, author, and availability status. Similarly, members will have personal information and a record of borrowed books. This fundamental structure allows for tracking both the library's inventory and its members' borrowing activities.

While a production system might include additional features like reservations, late fees, or categorization systems, our implementation focuses on the core functionality that demonstrates Harper's capabilities. The patterns established here can easily be extended for more complex requirements.

Getting Started with Harper

If you haven't installed Harper yet, refer to our previous article on Installing Harper where we covered three installation methods:

  • Global installation via npm
  • Running Harper in Docker
  • Offline installation for disconnected environments

Once you have Harper installed and running, create a new project directory and initialize it with Harper's application template:

With our project structure ready, we'll now define our GraphQL schema to establish our data model.

Defining Our Data Model

In your schema.graphql file, add the following:

This schema defines two entity types:

  • Book - Represents a library book with tracking for availability
  • Member - Represents a library patron with their borrowing history

The @table directive instructs Harper to create database tables for these types, while @export automatically exposes them through REST and GraphQL endpoints. Notice how declarative this is. We're defining both our database structure and API interfaces in a single file.

Implementing Resource Classes

Now let's create the business logic for our API by implementing resource classes in a resources.js file. These classes will handle the HTTP requests to our endpoints. We'll break down the code into manageable sections and explain each one.

The Books Resource Class

First, let's examine the Books class constructor:

This constructor extends Harper's Resource class and associates this resource with the Book table we defined in our GraphQL schema. Harper automatically creates a reference to this table in the tables object.

Next, let's look at the method for creating new books:

This post method handles creation of new books. It performs several important functions:

  • Data Parsing - Ensures the incoming data is properly formatted as an object
  • Default Values - Sets the book's availability to true by default
  • ID Protection - Removes any client-provided ID to prevent overriding system-generated IDs
  • Database Operation - Calls the table's post method to insert the record
  • Error Handling - Catches and formats any errors that might occur

The method automatically maps to HTTP POST requests to the /Book endpoint. Harper handles this routing for us based on class and method names.

Now, let's examine the method for retrieving books:

The get method handles requests to retrieve books. It's versatile, supporting both:

  • Fetching a specific book by ID (when an ID is provided in the URL)
  • Retrieving all books (when no ID is specified)

Harper's getId() method automatically extracts the ID from the request URL. This handles URLs like /Book/123 where 123 is the book ID.

Let's continue with the method for updating books:

The put method handles updating existing books. It follows a similar pattern to the post method, but with a key difference:

  • It requires an ID in the request data
  • It uses the table's put method, which updates a record rather than creating a new one

Finally, let's look at the method for deleting books:

The delete method removes a book from the database. It:

  1. Extracts the book ID from the URL
  2. Validates that an ID was provided
  3. Calls the table's delete method to remove the record
  4. Returns a success message or error details

With these four methods, we've created a complete API for managing books in our library.

The Members Resource Class

Now let's examine the Members class, which follows a similar pattern but with specific fields for member management:

Like the Books class, this constructor extends Harper's Resource class and associates with the Member table.

Next, let's look at the method for creating new members:

This method handles creation of new members. Unlike the Books class, it sets several member-specific default values:

  • membershipDate - Sets to today's date in YYYY-MM-DD format
  • status - Sets to "ACTIVE" by default
  • borrowedBooks - Initializes as an empty array

These defaults ensure that new members start with a consistent state, reflecting their real-world status in the library.

The method for retrieving members follows the same pattern as for books:

Similar to the Books class, this method supports both retrieving a specific member by ID and listing all members.

Next, let's examine the method for updating members:

This method validates the input, ensures an ID is provided, and uses the table's put method to update the member record.

Finally, let's look at the method for deleting members:

As with the Books class, this method removes a member from the database after extracting and validating the ID from the URL.

Testing Our Library Management System

Now that we've built our system, let's run it and test each component. Start your Harper instance:

Harper automatically:

  1. Creates the database tables based on our GraphQL schema
  2. Sets up the REST and GraphQL endpoints
  3. Connects our resource classes to these endpoints

Now you can make the HTTP calls to your service on http://localhost:9926/

Conclusion

In this article, we've built a Library Management System using Harper. We've implemented CRUD operations for both books and members, creating a foundation that can be extended with additional functionality as needed.

The power of Harper lies in its simplicity and efficiency. By defining our schema in GraphQL and implementing resource classes, we've created a full-featured API without the complexities of connecting separate database and API layers. The system we've built is:

  • Scalable - Can handle growing collections of books and members
  • Extensible - Built on patterns that can be expanded for new features
  • Maintainable - Organized in a clear, modular structure
  • Performant - Benefits from Harper's unified runtime

Whether you're building a small personal library tracker or a system for a public institution, Harper provides the tools you need to create robust, efficient APIs without unnecessary complexity.

You can extend this project and add more features, it’d be nice to see what you build.

In this article, we'll develop a complete Library Management System using Harper, demonstrating how this modern platform makes building robust APIs straightforward and efficient.

Understanding Our Library Management System

Before diving into the code, let's understand what our system will accomplish. We're building a Library Management System with two primary components:

  • Book Management - Creating, retrieving, updating, and deleting books in our library catalog
  • Member Management - Managing library patrons with similar CRUD (Create, Read, Update, Delete) operations

Each book in our system will have properties like title, author, and availability status. Similarly, members will have personal information and a record of borrowed books. This fundamental structure allows for tracking both the library's inventory and its members' borrowing activities.

While a production system might include additional features like reservations, late fees, or categorization systems, our implementation focuses on the core functionality that demonstrates Harper's capabilities. The patterns established here can easily be extended for more complex requirements.

Getting Started with Harper

If you haven't installed Harper yet, refer to our previous article on Installing Harper where we covered three installation methods:

  • Global installation via npm
  • Running Harper in Docker
  • Offline installation for disconnected environments

Once you have Harper installed and running, create a new project directory and initialize it with Harper's application template:

With our project structure ready, we'll now define our GraphQL schema to establish our data model.

Defining Our Data Model

In your schema.graphql file, add the following:

This schema defines two entity types:

  • Book - Represents a library book with tracking for availability
  • Member - Represents a library patron with their borrowing history

The @table directive instructs Harper to create database tables for these types, while @export automatically exposes them through REST and GraphQL endpoints. Notice how declarative this is. We're defining both our database structure and API interfaces in a single file.

Implementing Resource Classes

Now let's create the business logic for our API by implementing resource classes in a resources.js file. These classes will handle the HTTP requests to our endpoints. We'll break down the code into manageable sections and explain each one.

The Books Resource Class

First, let's examine the Books class constructor:

This constructor extends Harper's Resource class and associates this resource with the Book table we defined in our GraphQL schema. Harper automatically creates a reference to this table in the tables object.

Next, let's look at the method for creating new books:

This post method handles creation of new books. It performs several important functions:

  • Data Parsing - Ensures the incoming data is properly formatted as an object
  • Default Values - Sets the book's availability to true by default
  • ID Protection - Removes any client-provided ID to prevent overriding system-generated IDs
  • Database Operation - Calls the table's post method to insert the record
  • Error Handling - Catches and formats any errors that might occur

The method automatically maps to HTTP POST requests to the /Book endpoint. Harper handles this routing for us based on class and method names.

Now, let's examine the method for retrieving books:

The get method handles requests to retrieve books. It's versatile, supporting both:

  • Fetching a specific book by ID (when an ID is provided in the URL)
  • Retrieving all books (when no ID is specified)

Harper's getId() method automatically extracts the ID from the request URL. This handles URLs like /Book/123 where 123 is the book ID.

Let's continue with the method for updating books:

The put method handles updating existing books. It follows a similar pattern to the post method, but with a key difference:

  • It requires an ID in the request data
  • It uses the table's put method, which updates a record rather than creating a new one

Finally, let's look at the method for deleting books:

The delete method removes a book from the database. It:

  1. Extracts the book ID from the URL
  2. Validates that an ID was provided
  3. Calls the table's delete method to remove the record
  4. Returns a success message or error details

With these four methods, we've created a complete API for managing books in our library.

The Members Resource Class

Now let's examine the Members class, which follows a similar pattern but with specific fields for member management:

Like the Books class, this constructor extends Harper's Resource class and associates with the Member table.

Next, let's look at the method for creating new members:

This method handles creation of new members. Unlike the Books class, it sets several member-specific default values:

  • membershipDate - Sets to today's date in YYYY-MM-DD format
  • status - Sets to "ACTIVE" by default
  • borrowedBooks - Initializes as an empty array

These defaults ensure that new members start with a consistent state, reflecting their real-world status in the library.

The method for retrieving members follows the same pattern as for books:

Similar to the Books class, this method supports both retrieving a specific member by ID and listing all members.

Next, let's examine the method for updating members:

This method validates the input, ensures an ID is provided, and uses the table's put method to update the member record.

Finally, let's look at the method for deleting members:

As with the Books class, this method removes a member from the database after extracting and validating the ID from the URL.

Testing Our Library Management System

Now that we've built our system, let's run it and test each component. Start your Harper instance:

Harper automatically:

  1. Creates the database tables based on our GraphQL schema
  2. Sets up the REST and GraphQL endpoints
  3. Connects our resource classes to these endpoints

Now you can make the HTTP calls to your service on http://localhost:9926/

Conclusion

In this article, we've built a Library Management System using Harper. We've implemented CRUD operations for both books and members, creating a foundation that can be extended with additional functionality as needed.

The power of Harper lies in its simplicity and efficiency. By defining our schema in GraphQL and implementing resource classes, we've created a full-featured API without the complexities of connecting separate database and API layers. The system we've built is:

  • Scalable - Can handle growing collections of books and members
  • Extensible - Built on patterns that can be expanded for new features
  • Maintainable - Organized in a clear, modular structure
  • Performant - Benefits from Harper's unified runtime

Whether you're building a small personal library tracker or a system for a public institution, Harper provides the tools you need to create robust, efficient APIs without unnecessary complexity.

You can extend this project and add more features, it’d be nice to see what you build.

Learn how to create a full Library Management System using Harper. Define GraphQL schemas, implement resource classes, and build APIs without boilerplate code.

Download

White arrow pointing right
Learn how to create a full Library Management System using Harper. Define GraphQL schemas, implement resource classes, and build APIs without boilerplate code.

Download

White arrow pointing right
Learn how to create a full Library Management System using Harper. Define GraphQL schemas, implement resource classes, and build APIs without boilerplate code.

Download

White arrow pointing right

Explore Recent Resources

Blog
GitHub Logo

Answer Engine Optimization: How to Get Cited by AI Answers

Answer Engine Optimization (AEO) is the next evolution of SEO. Learn how to prepare your content for Google’s AI Overviews, Perplexity, and other answer engines. From structuring pages to governing bots, discover how to stay visible, earn citations, and capture future traffic streams.
Search Optimization
Blog
Answer Engine Optimization (AEO) is the next evolution of SEO. Learn how to prepare your content for Google’s AI Overviews, Perplexity, and other answer engines. From structuring pages to governing bots, discover how to stay visible, earn citations, and capture future traffic streams.
Colorful geometric illustration of a dog's head in shades of purple, pink and teal.
Martin Spiek
SEO Subject Matter Expert
Blog

Answer Engine Optimization: How to Get Cited by AI Answers

Answer Engine Optimization (AEO) is the next evolution of SEO. Learn how to prepare your content for Google’s AI Overviews, Perplexity, and other answer engines. From structuring pages to governing bots, discover how to stay visible, earn citations, and capture future traffic streams.
Martin Spiek
Sep 2025
Blog

Answer Engine Optimization: How to Get Cited by AI Answers

Answer Engine Optimization (AEO) is the next evolution of SEO. Learn how to prepare your content for Google’s AI Overviews, Perplexity, and other answer engines. From structuring pages to governing bots, discover how to stay visible, earn citations, and capture future traffic streams.
Martin Spiek
Blog

Answer Engine Optimization: How to Get Cited by AI Answers

Answer Engine Optimization (AEO) is the next evolution of SEO. Learn how to prepare your content for Google’s AI Overviews, Perplexity, and other answer engines. From structuring pages to governing bots, discover how to stay visible, earn citations, and capture future traffic streams.
Martin Spiek
Case Study
GitHub Logo

The Impact of Early Hints - Auto Parts

A leading U.S. auto parts retailer used Harper’s Early Hints technology to overcome Core Web Vitals failures, achieving faster load speeds, dramatically improved indexation, and an estimated $8.6M annual revenue uplift. With minimal code changes, the proof-of-concept validated that even small performance gains can unlock significant growth opportunities for large-scale e-commerce businesses.
Early Hints
Case Study
A leading U.S. auto parts retailer used Harper’s Early Hints technology to overcome Core Web Vitals failures, achieving faster load speeds, dramatically improved indexation, and an estimated $8.6M annual revenue uplift. With minimal code changes, the proof-of-concept validated that even small performance gains can unlock significant growth opportunities for large-scale e-commerce businesses.
Colorful geometric illustration of a dog's head resembling folded paper art in shades of teal and pink.
Harper
Case Study

The Impact of Early Hints - Auto Parts

A leading U.S. auto parts retailer used Harper’s Early Hints technology to overcome Core Web Vitals failures, achieving faster load speeds, dramatically improved indexation, and an estimated $8.6M annual revenue uplift. With minimal code changes, the proof-of-concept validated that even small performance gains can unlock significant growth opportunities for large-scale e-commerce businesses.
Harper
Sep 2025
Case Study

The Impact of Early Hints - Auto Parts

A leading U.S. auto parts retailer used Harper’s Early Hints technology to overcome Core Web Vitals failures, achieving faster load speeds, dramatically improved indexation, and an estimated $8.6M annual revenue uplift. With minimal code changes, the proof-of-concept validated that even small performance gains can unlock significant growth opportunities for large-scale e-commerce businesses.
Harper
Case Study

The Impact of Early Hints - Auto Parts

A leading U.S. auto parts retailer used Harper’s Early Hints technology to overcome Core Web Vitals failures, achieving faster load speeds, dramatically improved indexation, and an estimated $8.6M annual revenue uplift. With minimal code changes, the proof-of-concept validated that even small performance gains can unlock significant growth opportunities for large-scale e-commerce businesses.
Harper