Skip to content

prtvi/joke-api

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Joke API using Golang and MongoDB

A simple API built using the Echo framework in Golang.

USING THE API

Types of jokes

type: identifier of group/type of joke

# Type
1 General
2 Knock-Knock
3 Programming

Getting Started

Endpoint What it does
GET /random Returns a joke object that contains a setup, punchline, type and id
GET /random/:n Returns an array with up to 44 joke objects.
GET /joke/:id Returns a joke object with a specific id.
POST /new Provided a setup, punchline and type it will insert the joke into the db.
DELETE /remove/:id Remove a joke with the given id
UPDATE /update/:id Provided a new setup or punchline or type it will update the joke with the given id.

API calls

This API supports a data response in JSON format.

/random

{
  "id": 43,
  "type": "general",
  "punchline": "To prove that he was framed!",
  "setup": "Why did the burglar hang his mugshot on the wall?"
}

/random/:count

count: number of jokes to be fetched

/random/2

[
  {
    "id": 8,
    "type": "general",
    "punchline": "To get to the other slide.",
    "setup": "Why did the kid cross the playground?"
  },
  {
    "id": 40,
    "type": "general",
    "punchline": "Lots of training",
    "setup": "How do locomotives know where they're going?"
  }
]

/joke/:id

id: unique identifier for a joke

/joke/1

[
  {
    "id": 1,
    "type": "general",
    "setup": "What did the fish say when it hit the wall?",
    "punchline": "Dam."
  }
]

/new

Post request body:

{
  "setup": "this is a test",
  "punchline": "this is a funny test",
  "type": "test"
}

Response

{
  "responseMsg": "Success",
  "statusCode": 200,
  "joke": {
    "id": 134,
    "setup": "this is a test",
    "punchline": "this is a funny test",
    "type": "test"
  }
}

/remove/:id

/remove/3

{
  "statusCode": 200,
  "message": "Delete operation successful!"
}

/update/:id

/update/3

Request body

{
  "type": "general",
  "punchline": "Guilty",
  "setup": "Do I enjoy making courthouse puns?"
}

Response

{
  "responseMsg": "Success",
  "statusCode": 200,
  "joke": {
    "id": 3,
    "type": "general",
    "punchline": "Guilty",
    "setup": "Do I enjoy making courthouse puns?"
  }
}

Other links

Click here to check out my other projects

About

A simple REST API for jokes. Built in Golang - Echo framework

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors