Coder Social home page Coder Social logo

bookrestapi's Introduction

bookrestapi

This is a rest api application built in go (golang) with postgresql database and the net/http package from the standard library. The goal was to build the application without using any external library other than the ones in the standard library. The only external package that was used is the pq (postgres "github.com/lib/pq") driver since there is no way to interact with a database without using an external driver as of this time.

How to run the application

  1. Clone the application with https://github.com/emanuelquerty/bookrestapi.git

  2. Use the postgres dump books_db.sql to create the database, create the tables and insert some dump data.

  3. Once the application is cloned and database is created, change the Connection String as per your postgres username, password and database name on line No. 12 in /pkg/db/database.go

  4. Before running the application, you need to import the pq (postgres) driver that the database/sql package requires. To do that, just run the following command in your terminal:

        go get "github.com/lib/pq"
  5. To run the application, please use the following command:

       go run main.go

    Note: By default the server is listening on port 3000.

Endpoints Description

Get All Books

    URL - *http://localhost:3000/api/v1/books*
    Method - GET

Get Book By ID

    URL - *http://localhost:3000/api/v1/books/2*
    Method - GET

Create a new Book Entry

    URL - *http://localhost:3000/api/v1/books*
    Method - POST
    Body - (content-type = application/json)
    {
        "title": "Rennaissance",
        "published_year": 2022,
        "author_id": 2
    }

Update Entry

    URL - *http://localhost:3000/api/v1/books/2*
    Method - PUT
    Body - (content-type = application/json)
   {
        "title": "This is a new updated title",
        "published_year": 1840,
        "author_id": 2
    }

Delete Entry

    URL - *http://localhost:3000/api/v1/books/2*
    Method - DELETE

Hope everything works. Thank you.

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.