GithubHelp home page GithubHelp logo

project-mongo-api's Introduction

Mongo API Project ๐Ÿ™

I've built a RESTful API using a database to store and retrieve data.

I used MongoDB for the database, mongoose for the modelling of data and Express.js (Node.js framework).

The problem

The main task was to build a RESTful API and to use a database to store and retrieve data.

I started with setting up the database using MongoDB and built a model for the data that I chose (books data) using mongoose. After that I set up an async function to seed the database using the aforementioned mongoose model with an if statement around it to ensure that the database is only being reseeded when I want it to. With the database in place I began thinking about what kind of endpoints I would like to have for the data. I then started to create the endpoints home, all books, books by top rating (4 or higher), short read and id. I also implemented filters via query parameters to filter, via mongoose, the data returned from endpoints which then return an array of data.

I've also implemented error handling throughout the project. For instance, when searching for a book by id, I've set up an if statement to handle when the specific id doesn't exist and return some useful data in the response instead. I've also implemented try and catch blocks.

I chose to use the npm package express-list-endpoints to list the endpoints in the home endpoint. I continuously tested my API using Postman and checked out my database using MongoDB Compass.

If I had more time, I would implement a frontend to by API where I display the documentation for my API. I would also like to implement pages to return only a selection of results from the array and to use mongoose's aggregate function.

View it live

Link to my deployed API: https://project-mongo-api-isabellam5.herokuapp.com/

Documentation

ENDPOINTS

  • GET /

Displays all endpoints for this API using npm package express-list-endpoints.

BOOKS

  • GET /books
  • GET /books/toprating
  • GET /books/shortread

Endpoints for the API.

SINGLE BOOK

  • GET /books/:bookId

Endpoint for a single book by id.

QUERIES

Use endpoint GET /books

Filter by either author or title (optional). Case insensitive.

  • Example query for author: GET /books?author=adams
  • Example query for title: GET /books?title=bill
  • Example query for isbn: GET /books?isbn=439785960

project-mongo-api's People

Contributors

emolsz avatar isabellam5 avatar dependabot[bot] avatar idlefingers avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.