Skip to content

meetKazuki/address-book

Repository files navigation

Address Book API

This repository houses code for Address Book's backend.

Table of Contents

About the Project

This is a simple RESTful API for an address book. Part of an online assessment for STRV. It allows a user to:

  • Register a new account.
  • Log in to the created.
  • Add a contact to Firebase

Folder Structure

.
├── .github                     # Compiled files
├── database                    # Database migration scripts and seeders
├── docs                        # Documentation files
├── src                         # Source files
├── test                        # Automated tests
├── .env.example
├── LICENSE
├── package.json
└── README.md

HTTP Response Codes

Each response will be returned with one of the following HTTP status codes:

  • 200 OK The request was successful
  • 400 Bad Request There was a problem with the request (security, malformed)
  • 401 Unauthorized The supplied API credentials are invalid
  • 403 Forbidden The credentials provided do not have permissions to access the requested resource
  • 404 Not Found An attempt was made to access a resource that does not exist in the API
  • 500 Server Error An error on the server occurred

Sample HTTP Response

The API response, to the best of my ability, is structure after JSEnd specifications.

  • For a success response, the server will return a response of this format:
{
  "status": "success",
  "message": "success message from the API server"
  "data": { ... }
}
  • For an error response, the server will return a response of this format. The trace key in the error object is returned if NODE_ENV === development.
{
  "status": "error",
  "error": {
    "message": "error message from the API server",
    "trace": {
      "statusCode": <status-code>
    }
  }
}

Project Status

Run in Postman Deploy to Heroku Staging

Project Payload

Getting Started

Dependencies

This project uses Express.js v4.17. It has the following dependencies:

Third party Services

  • Firebase Admin for storing contacts.
  • Github Actions for Continuous Integration and Deployment.
  • Heroku for hosting the API.

Getting the Source

This project is hosted on Github. You can clone this project directly using this command:

git clone https://github.com/meetKazuki/address-book.git

Installation & Usage

  • Create a PostgreSQL database by running the cmd below:
createdb -h localhost -p 5432 -U postgres <database_name>
  • After cloning the repository, create a .env file from .env.example and set your local .env. variable(s).
cp .env.example .env
  • Install the dependencies
npm install
  • Run migration
npm run db:migrate
  • You can run the server using
npm run dev
  • Other npm scripts are also available for handling database migration and database seeding:
    • npm run db:migrate runs script that is responsible for creating tables and their columns in the database,
    • db:migrate:undo: undoes the effect of npm run db:migrate,
    • db:reset: undoes all the migrations, then runs migration on the database,
    • db:seed: responsible for seeding records in the database,

Running Tests

To run tests, run

npm test

How to Get Help

Notice a bug? Please open an issue. Need more clarification on any part of the code base? Contact Desmond.

Contributing

To contribute to this project, start by raising an issue. There are issue templates for bug and feature request. Once this issue has been agreed upon, you can create a feature or hotfix branch off develop or master (for hotfix) and raise PR. There is also a PR template.

License

This project is licensed under the MIT License

Authors

Releases

No releases published

Packages

No packages published