Code Monkey home page Code Monkey logo

personal-blog-api's Introduction

Go REST API for my personal blog

My first Golang project, a REST API to support my personal blog (Under development ๐Ÿ˜‰ )

Getting Started

Although this was meant as project for myself to use on my personal blog, feel free to clone it as boilerplate code for a MUX-MongoDB project.

Prerequisites

Of course, you'll need to have golang installed https://golang.org/dl/ (I use version 1.12.1, if you're using a different version please change the "go-version" in the go.mod file. Additionally, for dependency management, this project uses go modules!

$ git clone https://github.com/tarikeshaq/personal-blog-API.git

Since this project used go modules, you don't need to place it in your GOPATH ๐Ÿ˜„ Simply clone the project and run it!

NOTE: You'd need Go 1.11+ in order to run this using go modules

Installing

With the repo downloaded, you'll be able to run in no time! navigate to the cloned repo, and pull the dependencies by running go build

$ go build

This will create the binary and make sure all the dependencies are correct (Will download any dependencies you don't have, yay go modules)

Now, you'll have the project ready, but you do need to set some Environment (OS) variables

* "PORT": Environment variable to point to the port where you'd like the server to run
* "MONGO_HOST": Your mongoDB host, find the URI for your database and the host would be after the '@' and before the '/'
* "MONGO_USERNAME": Your mongoDB database username
* "MONGO_PASSWORD": Your mongoDB database password for the above username
* "MONGO_DATABASE": The name of the database (I have mine as blogs)

With that the application should be ready for you take on a ride!! Make sure that your MongoDB server is running, then run the following:

$ go run main.go

With that the server should be running and ready to be queried

API End points

* GET /blogs : Returns all the blog posts in the database
* GET /blogs/{blogId} : Returns one post from the database with id = blogID
* POST /blogs : Adds a blog post to the database
* DELETE /blogs/{blogId} : Deletes a blog post from the database with id = blogID

To check the structure of a blog post, check the /models directory

Deployment

I have my application deployed on Heroku

You can deploy on heroku by adding your repository from the heroku site, or using the CLI

Built With

Contributing

This a personal project, although, if you feel like you see a way to improve it, feel free to create a PR :)

Authors

  • Tarik Eshaq - Project Owner

License

This project is licensed under the MIT License - see the LICENSE.md file for details

Acknowledgments

  • Mad respect to everyone who's code I sto.. got influenced by ๐Ÿ‘ผ
  • Go has been an amazing techology to learn, definitly will build more stuff using it!

personal-blog-api's People

Stargazers

 avatar

Watchers

 avatar  avatar

Forkers

peaceblues

personal-blog-api's Issues

Add tests

Unit tests for

  • All Route handlers

  • All Queries

Add support for Comments

This is closely coupled with #6 and cannot really happen until that's done

  • Adjust Post schema to have a list of comments
  • Create comment schema with username, timestamp, and content
  • Add RESTFul handling to Add, Remove and Update comments (With auth middleware)

Add support for users

Only for comments, nothing too fancy

  • Auth using username and password

  • Hash username and password

  • Match hashes against DB in fixed time compare

  • Maintain a session Cookie

  • Protect future comment api's with this middleware

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.