Socket
Socket
Sign inDemoInstall

github.com/aayush1607/instagram_api

Package Overview
Dependencies
12
Alerts
File Explorer

Install Socket

Detect and block malicious and high-risk dependencies

Install

    github.com/aayush1607/instagram_api


Version published

Readme

Source

✨Instagram APIs ✨

The task given by Appointy completed to develop APIs for a basic version of Instagram.

Create an User
Get User by Id
Create a Post
Get a Post by Id
Get all Posts by an User with Pagination

Setup:

STEP-1 : Install and Set Up MongoDB
            https://docs.mongodb.com/v5.0/installation/
STEP-2 : Clone this repository
            git clone https://github.com/aayush1607/instagram_api.git
            cd instagram-api
STEP-3 : Run local MongoDB instance
            mongo
STEP-4 : Download Dependencies
            go mod download
STEP-5 : Finally Run the Server
            go run main.go
STEP-6 : Then simply navigate in your browser or test the above mentioned APIs on Postman or CURL

APIs :

  1. Create an User
    Method Allowed-POST
    URL http://localhost:8080/users
    JSON Request Body
    {
        "Name":"aayush",
        "Email":"auc1607@gmail.com",
        "Password": "aayush@1234"
    }
    
    JSON Response Body
    {
        "InsertedID": "61617acff3b743f10bb0923a"
    }
    
  2. Get User By id
    Method Allowed-GET
    URL http://localhost:8080/users/?id=61617acff3b743f10bb0923a
    JSON Response Body
    {
        "_id": "61617acff3b743f10bb0923a",
        "name": "aayush",
        "email": "auc1607@gmail.com",
        "password": "$2a$10$NI5Ub2L2jIePsJu8ljOjBeK.LtfdTj5OoaWV.G7XqU3zuhAF/inCS"
    }
    
  3. Create a Post
    Method Allowed-POST
    URL http://localhost:8080/posts
    JSON Request Body
    {
        "User": "61615ad9d9a12f1927083b7f",
        "Caption": "Hello Instagram 4",
        "Image_url": "www.insta.com",
        "Timestamp": ""
    }
    
    JSON Response Body
    {
        "InsertedID": "61616540d9fbb9baedcff879"
    }
    
  4. Get a Post by id
    Method Allowed-GET
    URL http://localhost:8080/posts/?id=61616540d9fbb9baedcff879
    JSON Response Body
    {
        "_id": "61616540d9fbb9baedcff879",
        "user": "61615ad9d9a12f1927083b7f",
        "caption": "Hello Instagram 4",
        "image_url": "www.insta.com",
        "timestamp": "2021-10-09T09:47:44.93Z"
    }
    
  5. Get all Posts by user id with pagination
    (limit is the number of posts per page and page is the page number you want to visit. If limit and page parameters are not provided then by default they will be taken as 1)
    Method Allowed-GET
    URL http://localhost:8080/posts/users/?id=61615ad9d9a12f1927083b7f&limit=2&page=1
    JSON Response Body
    {
        "posts": [
            {
                "_id": "6161616aa66d684e5bb38fbc",
                "user": "61615ad9d9a12f1927083b7f",
                "caption": "Hello Instagram",
                "image_url": "www.insta.com",
                "timestamp": "0001-01-01T00:00:00Z"
            },
            {
                "_id": "616161e885e8e66798b7ed78",
                "user": "61615ad9d9a12f1927083b7f",
                "caption": "Hello Instagram 2",
                "image_url": "www.insta.com",
                "timestamp": "2021-10-09T09:33:28.758Z"
            }
        ],
        "total": 4,
        "page": 1,
        "last_page": 2,
        "limit": 2
    }
    

Packages Used

  1. MongoDB Go Driver to work with mongodb database
  2. Bcrpyt to hash passwords
  3. net/http for response request and response writer
  4. encoding/json for encoding and decoding from json to type struct and vice versa
  5. time for saving current timestamps if not provided by frontend interface

Languages & Tools Used

              

FAQs

Last updated on 09 Oct 2021

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc