go-rest-api

command module
v0.0.0-...-f1d2707 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 29, 2019 License: MIT Imports: 9 Imported by: 0

README

Go-REST-API

Yet another REST API written in Go with connection to PostgreSQL database

Install

Make sure Go is already installed on your PC.

Clone this repository and install all required dependencies.

Setup

Database

Create a PostgreSQL database and then create following table (all code is auto-generated by pgAdmin):

CREATE TABLE public.posts
(
    id integer NOT NULL,
    author integer NOT NULL,
    posted_at timestamp without time zone NOT NULL,
    title text COLLATE pg_catalog."default" NOT NULL,
    text text COLLATE pg_catalog."default" NOT NULL,
    CONSTRAINT posts_pkey PRIMARY KEY (id)
)
Environment variables

Create config.env file and setup the following variables:

db_user = *your_username*
db_pass = *your_password*
db_name = *your_database_name*
db_host = localhost
db_port = *postgres_server_port*

Start

Type the following code in the terminal:

go run .

Send requests

Open Postman or another software to sending HTTP-requests and send them to the following address:

http://localhost:8080/api/v1/
API Pages
  • addPost - POST method - creates a single post in the database
  • getPost - GET method - gets a single post from the database by id
  • getPosts - GET method - gets n-posts from the database if n is set; otherwise gets all existing posts, ordered by the publication time
  • updatePost - PUT method - updates a single post from the database by id
  • deletePost - DELETE method - deletes a single post from the database by id

Documentation

The Go Gopher

There is no documentation for this package.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL