/go-news-api

Golang rest-api practice

Primary LanguageGoMIT LicenseMIT

API-PRACTICE

License

Functional

  • CRUD news.
  • CD comment.

Endpoint's

HTTP URLBODYRESPONSE
GET/api/v1/news -
[
  {
    "id": 3,
    "title": "Title",
    "description": "Desc",
    "comments": null
  },
  {
    "id": 4,
    "title": "kek",
    "description": "Desc",
    "comments": null
  }
]
POST/api/v1/news
{
  "title": "Test"
}
{
  "id": 5,
  "title": "Test",
  "description": "",
  "comments": null
}
GET/api/v1/news/{id}-
{
  "id": 4,
  "title": "kek",
  "description": "Desc",
  "comments": [
    {
      "id": 13,
      "text": "Text",
      "news_id": 4
    }
  ]
}
DELETE/api/v1/news/{id}-
{
  "id": 5,
  "title": "Test",
  "description": "",
  "comments": null
}
PUT/api/v1/news/{id}
{
  "title": "Test"
}
{
  "id": 4,
  "title": "Test",
  "description": "Desc",
  "comments": null
}
POST/api/v1/comments
{
  "text": "Text",
  "news_id": 4
}
{
  "id": 14,
  "text": "Text",
  "news_id": 4
}
DELETE/api/v1/comments/{id}-
"Comment Deleted Successfully!"

Technologies

  • Language: Go
  • Libraries: Viper, GORM, Mux
  • Database: MySQL

Installing

Firstly clone the project.

git clone https://github.com/l1ve4code/go-news-api

Secondly run project.

go run .

Author