Member-only story

Creating a Golang REST API Using the Webframework + Router Chi — Learning Golang

Izzat Arramsyah
2 min readSep 17, 2020

--

image from google.com

INTRODUCTION

Hello Everyone
In this article, I would like to share a tutorial on creating a REST API in Golang using the Webframework + Router Chi and the NoSQL MongoDB database.

PREREQUISITE

If you don’t have MongoDB yet, you can download it first. You can click here to download.

Install the MongoDB and Chi Router packages first for our coding needs this time. You can open your command prompt and type the following commands.

go get -u github.com/go-chi/chi
go get go.mongodb.org/mongo-driver

PROJECT STRUCTURE

We will create the project structure first to separate between layers. Here, I’m using the Repository, Services, and Controller pattern to make it easier to develop. Below is an example of the folder structure that I am using.

-ProjectGO
--pkg
--src
--controller
--EmployeeController.go
--interfaces
--EmployeeRepository.go
--ServicesRepository.go
--models
--Employee.go
--Response.go
--repository
--EmployeeRepositoryImpl.go
--services
--EmployeeServicesImpl.go
--main.go

MODELS

--

--

No responses yet