Skip to content

Starter template for a mux http server with extras

Notifications You must be signed in to change notification settings

remuspoienar/go-mux-template

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

HTTP Mux Starter

Simple MUX template project

Provides starting point for a REST API

  • context
  • JWT Auth + middleware
  • bcrypt helper
  • webhooks integration
  • godotenv (env sample file provided)
  • static file serving
  • fs storage (JSON format)

Auth endpoints

Content-Type: application/json
{
  "email": "mike@example.com",
  "password": "hunter200"
}

Returns 200 OR 401

{
  "id": 1,
  "email": "mike@example.com",
  "is_chirpy_red": false,
  "token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c",
  "refresh_token": "56aa826d22baab4b5ec2cea41a59ecbba03e542aedbb31d9b80326ac8ffcfa2a"
}

Returns a JWT with a refresh token passed in headers

Authorization: Bearer b056cec97994e74e6695eba938cee97513eaeb720829559812066272f5529c17

Returns 200 OR 401

{
  "token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c"
}

Revokes a refresh token

Authorization: Bearer b056cec97994e74e6695eba938cee97513eaeb720829559812066272f5529c17

Returns 204 OR 401

User endpoints

Creates a user

Content-Type: application/json
{
  "password": "hunter200",
  "email": "mike@example.com"
}

Returns 201

{
  "email": "mike@example.com",
  "id": 6,
  "is_chirpy_red": false
}

Updates a user

Content-Type: application/json
Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJjaGlycHkiLCJzdWIiOiIxIiwiZXhwIjoxNzIwMjE1NTIxLCJpYXQiOjE3MjAyMTE5MjF9.dpLB975ewERQ5tXrYF7oLYicQyzXl27Rt3HadrgkJzg
{
  "email": "new_mike@example.com"
}

Returns 200 OR 401

{
  "email": "new_mike@example.com",
  "id": 6,
  "is_chirpy_red": false
}

Chirps

Gets all chirps

Optional query parameters

GET /api/chirps?sort=asc
GET /api/chirps?sort=desc
GET /api/chirps?author_id=3

Returns 200 OR 400 (if query params are invalid)

[
  {
    "body": "Darn that fly, I just wanna cook",
    "id": 4,
    "author_id": 1
  },
  {
    "body": "Cmon Pinkman",
    "id": 3,
    "author_id": 2
  },
  {
    "body": "Gale!",
    "id": 2,
    "author_id": 1
  },
  {
    "body": "I'm the one who knocks!",
    "id": 1,
    "author_id": 4
  }
]

Creates a chirp

Content-Type: application/json
Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJjaGlycHkiLCJzdWIiOiIxIiwiZXhwIjoxNzIwMjE1NTIxLCJpYXQiOjE3MjAyMTE5MjF9.dpLB975ewERQ5tXrYF7oLYicQyzXl27Rt3HadrgkJzg
{
  "body": "Last time i went to Rustbucks ! #til"
}

Returns 200 OR 400(if length is > 140)

{
  "id": 22,
  "body": "Last time i went to Rustbucks ! #til",
  "author_id": 2
}

Gets a chirp by id

Returns 200 OR 404

{
  "id": 4,
  "body": "Darn that fly, I just wanna cook",
  "author_id": 1
}

Delete a chirp by id - Only the author can perform this and will result in a 403 otherwise

Returns 204, 403 OR 404

Payment event webhook

Uses api key auth

Authorization: ApiKey <string>
{
  "event": "user.upgraded",
  "data": {
    "user_id": 3
  }
}

Returns 204 OR 404

About

Starter template for a mux http server with extras

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published