DEV Community

Cover image for Build a REST API with Golang and MongoDB - Fiber Version

Build a REST API with Golang and MongoDB - Fiber Version

Demola Malomo on January 03, 2022

Representational state transfer (REST) is an architectural pattern that guides an Application programming interface(API) design and development. RE...
Collapse
 
habeebullahtabrez profile image
Mohammed Habeeb Ullah Tabrez

I am a nodejs developer and I was assigned to make one rest API in go. I came across this article tutorial and this was the best tutorial to implement a REST API with all the CRUD operations in go. Loved it, Keep growing! <3

Collapse
 
malomz profile image
Demola Malomo

Thanks for the kind words.

Glad the article helped :)

Collapse
 
muhammadali208 profile image
Muhammad Ali

good work

Collapse
 
varun11 profile image
varun Aryan

Thanks sir, go is best for Web api's

Collapse
 
josesan94 profile image
José Santillan

Extremelly helpful for those who are starting with GO. Congratulations! Keep it that way

Collapse
 
nutniti1 profile image
Nutniti Suteerapongpan

Hi ,
Thank you for sharing.


Could I ask you more question ?
I am trying to deploy it on Heroku.

But it shows :
github.com/{myname}/fiber-mongo-api/configs
! Push rejected, failed to compile Go app.
! Push failed

What should I do to make it able to run on Heroku server?

Collapse
 
malomz profile image
Demola Malomo

Hi,

I'm glad you enjoyed reading the article.

I haven’t deployed on Heroku before.
These resources might help

devcenter.heroku.com/articles/gett...

dev.to/heavykenny/how-to-deploy-a-...

Collapse
 
surajtecho profile image
surajtecho

when i follow this doc and implemented it run succesfully again when i close my pc and run again
its showing
main.go:6:5: cannot find package "github.com/gofiber/fiber/v2" in any of:
C:\Program Files\Go\src\github.com\gofiber\fiber\v2 (from $GOROOT)
C:\Users\Techolution\go\src\github.com\gofiber\fiber\v2 (from $GOPATH)

it is happening again and again i tried to build and run it run succesfully when i tried to close my pc and run again its showing same

Collapse
 
malomz profile image
Demola Malomo

Hi @surajtecho
According to the error, It looks like the fiber package is not installed.

try reinstalling the package using: "go get -u github.com/gofiber/fiber/v2"

Collapse
 
medlabs profile image
MedLabs

why using a dedicated file for every response type ?
maybe putting all the responses types in one file would be better

Collapse
 
maprangsoft profile image
Maprangsoft

thank you very much i will use on production.

Collapse
 
snelson1 profile image
Sophia Nelson

Very good stuff

Collapse
 
4nth0ny1 profile image
Anthony C

Has anyone gotten a status 400, unprocessible entity on post requests and resolved it?

Collapse
 
kidmtt94 profile image
kidmtt94

Hi,

You create new user ID with primitive.NewObjectID().
What if two requests are executed at the same time (concurrency case)

Collapse
 
raphoester profile image
Info Comment hidden by post author - thread only accessible via permalink
raphoester

This way of coding is absolutely NOT how go is meant to be used. You are supposed to convert your functions in methods and implement interfaces in your packages.

Collapse
 
vrashabhsontakke profile image
Vrashabh Sontakke

I am struggling to create a dockerfile for this project. Please help me create one

Collapse
 
realnsleo profile image
Arnold Babasa

Did you manage to figure this out?

Some comments have been hidden by the post's author - find out more