mtlh / go-vercel-postgres

Instructions on how to create an api layer with Go, all hosted on vercel and connecting to a postgres database.

Home Page:https://go-vercel-postgres.vercel.app/api

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Go + Vercel Functions + Postgres

Instructions on how to create an API layer with Go and common usage routes, all hosted on vercel and connecting to a postgres database.

Go Vercel Postgres

Routes

/api

https://go-vercel-postgres.vercel.app/api
Index for application, holding basic application information.

/api/date

https://go-vercel-postgres.vercel.app/api/date
Get current date string.

/api/dbget

https://go-vercel-postgres.vercel.app/api/dbget
Connect to the postgres instance and retrieve id and name fields in the "USERS" table.

/api/dbdelete/id

https://go-vercel-postgres.vercel.app/api/dbdelete/1
Connect to the postgres instance and delete record using id variable in the "USERS" table.

/api/dbinsert/name

https://go-vercel-postgres.vercel.app/api/dbinsert/testingname
Connect to the postgres instance and insert record using name variable and incremented id, in the "USERS" table.

/api/dbupdate/id/name

https://go-vercel-postgres.vercel.app/api/1/updatedname
Connect to the postgres instance and update record using name and id variables, in the "USERS" table.

Getting Started

  1. Clone the repo:

     git clone https://github.com/mtlh/go-vercel-postgres.git
  2. Create .env file with the following fields:

     PGHOST='hosturl'
     PGDATABASE='db'
     PGUSER='user'
     PGPASSWORD='pass'
    
  3. Link to Vercel:

    npm -g vercel
    vercel --prod
    

About

Instructions on how to create an api layer with Go, all hosted on vercel and connecting to a postgres database.

https://go-vercel-postgres.vercel.app/api


Languages

Language:Go 100.0%