Git Product home page Git Product logo

go-sample's Introduction

golang heroku deploy

This is a simple restful api project that deployed to heroku. You can access it with this url:

https://golang-heroku.herokuapp.com

Find the tutorial here:

https://www.youtube.com/watch?v=_EAkLIoMCNM

Documentation

health

to check current server is alive:

GET

https://golang-heroku.herokuapp.com/api/check/health

Response (Status: 200)

{
   message: "OK!"
}

register

Registering a new user

POST

https://golang-heroku.herokuapp.com/api/auth/register

Request Body

{
    "name": "Prieyudha Akadita S",
    "email": "[email protected]",
    "password": "yudhanewbie"
}

Response success (Status: 201)

{
    "status": true,
    "message": "OK!",
    "errors": null,
    "data": {
        "id": 2,
        "name": "Prieyudha Akadita S",
        "email": "[email protected]",
        "token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VyX2lkIjoiMiIsImV4cCI6MTY1MTgyMDAwMCwiaWF0IjoxNjIwMjg0MDAwLCJpc3MiOiJhZG1pbiJ9.HtnuWlBaevEO3fHAI4McH5W8axvw_3Og47RUI3m9IyI"
    }
}

Response error (Status : 400) [Depends on what error]

{
    "status": false,
    "message": "Failed to process request",
    "errors": [
        "Key: 'RegisterRequest.Name' Error:Field validation for 'Name' failed on the 'required' tag"
    ],
    "data": {}
}

login

Authenticate by email and password

POST

https://golang-heroku.herokuapp.com/api/auth/login

Request body

{
    "email": "[email protected]",
    "password": "yudhanewbie"
}

Response Success (Status: 200)

{
    "status": true,
    "message": "OK!",
    "errors": null,
    "data": {
        "id": 1,
        "name": "Prieyudha Akadita S",
        "email": "[email protected]",
        "token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VyX2lkIjoiMSIsImV4cCI6MTY1MTgyMTQ0NiwiaWF0IjoxNjIwMjg1NDQ2LCJpc3MiOiJhZG1pbiJ9.2m-r1qrCXhNkAxzK-sb4hL0Pzat3zwOmzktES_uzwts"
    }
}

Response error, wrong credential (Status: 401)

{
    "status": false,
    "message": "Failed to login",
    "errors": [
        "failed to login. check your credential"
    ],
    "data": {}
}

Get Profile

Get current info from logged user

GET

https://golang-heroku.herokuapp.com/api/user/profile

Headers

Authorization: yourToken

Response success (status: 200)

{
    "status": true,
    "message": "OK",
    "errors": null,
    "data": {
        "id": 1,
        "name": "Prieyudha Akadita S",
        "email": "[email protected]"
    }
}

Update profile

Update user data who logged in

PUT

https://golang-heroku.herokuapp.com/api/user/profile

Headers

Authorization: yourToken

Request Body

{
    "name": "Prieyudha Akadita S",
    "email": "[email protected]"
}

Response success (Status: 200)

{
    "status": true,
    "message": "OK",
    "errors": null,
    "data": {
        "id": 1,
        "name": "Prieyudha Akadita S",
        "email": "[email protected]"
    }
}

=============================================

All tweets (based on user who logged in)

Only shows tweets by user who logged in

GET

https://golang-heroku.herokuapp.com/api/tweet

Headers

Authorization: yourToken

Response success (Status: 200)

{
    "status": true,
    "message": "OK!",
    "errors": null,
    "data": [
        {
            "id": 2,
            "tweet_name": "Xiaomi Redmi 10",
            "price": 3000,
            "user": {
                "id": 1,
                "name": "Prieyudha Akadita S",
                "email": "[email protected]"
            }
        },
        {
            "id": 3,
            "tweet_name": "Indomie Goreng",
            "price": 2500,
            "user": {
                "id": 1,
                "name": "Prieyudha Akadita S",
                "email": "[email protected]"
            }
        }
    ]
}

Create tweet

Create a tweet with owner is the user who logged in

POST

https://golang-heroku.herokuapp.com/api/tweet

Headers

Authorization: yourToken

Request body

{
    "name": "Xiaomi Redmi 5",
    "price": 3000
}

Response success (Status: 201)

{
    "status": true,
    "message": "OK!",
    "errors": null,
    "data": {
        "id": 1,
        "tweet_name": "Xiaomi Redmi 5",
        "price": 3000,
        "user": {
            "id": 1,
            "name": "Prieyudha Akadita S",
            "email": "[email protected]"
        }
    }
}

Find one tweet by id

Find tweet by id

GET

https://golang-heroku.herokuapp.com/api/tweet/{id}

Headers

Authorization: yourToken

Response success (Status: 200)

{
    "status": true,
    "message": "OK!",
    "errors": null,
    "data": {
        "id": 1,
        "tweet_name": "Xiaomi Redmi 5",
        "price": 3000,
        "user": {
            "id": 1,
            "name": "Prieyudha Akadita S",
            "email": "[email protected]"
        }
    }
}

Update tweet

You can only update your own tweet If you are trying to update someone else tweet, it will return error.

PUT

https://golang-heroku.herokuapp.com/api/tweet/{id}

Request body

{
    "name": "Xiaomi Redmi 5 Plus",
    "price": 5000
}

Response success (Status: 200)

{
    "status": true,
    "message": "OK!",
    "errors": null,
    "data": {
        "id": 1,
        "tweet_name": "Xiaomi Redmi 5 Plus",
        "price": 5000,
        "user": {
            "id": 1,
            "name": "Prieyudha Akadita S",
            "email": "[email protected]"
        }
    }
}

Delete tweet

You can only delete your own tweet

DELETE

https://golang-heroku.herokuapp.com/api/tweet/{id}

Response success (Status: 200)

{
    "status": true,
    "message": "OK!",
    "errors": null,
    "data": {}
}

go-sample's People

Contributors

ikeda1729 avatar ydhnwb avatar

Watchers

 avatar

go-sample's Issues

Tweetsテーブル追加

既存のproductsテーブルがuserに紐付いているため、
これを修正してtweetsテーブルにする

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.