Dad Jokes API for PTCT Build Week, November 2019, deployed at https://lambda-dad-jokes.herokuapp.com
Log an user in, receive token on successful login
POST /api/auth/login
Name | Type | Description |
---|---|---|
username | String | The User's username |
password | String | The User's password |
(json) Sample-Request:
{
"username": "johndoe",
"password": "123456"
}
Success-Response:
{
"message": "Welcome back johndoe!",
"token": "Generated Token"
}
Name | Type | Description |
---|---|---|
message | json | Welcome Message |
Error-Response:
{
"username": "Required"
}
Error-Response:
{
"code": 404,
"error": "User Not Found"
}
Error-Response:
{
"code": 401,
"error": "Invalid Credentials"
}
Registers a New User to the Database
POST /api/auth/register
Name | Type | Description |
---|---|---|
String | The User's Email |
|
username | String | The User's Username |
password | String | The User's Password |
(json) Sample-Request:
{
"email": "john@doe.com",
"username": "johndoe",
"password": "123456"
}
Success-Response:
{
"message": "Welcome to Dad Jokes johndoe"
}
Name | Type | Description |
---|---|---|
message | json | Welcome Message |
Error-Response:
{
"username": "Required"
}
Error-Response:
{
"code": 400,
"error": "Username is already taken"
}
Error-Response:
{
"code": 400,
"error": "Email is already taken"
}
Delete the Joke with the Provided Id
DELETE /api/jokes/:id
Name | Type | Description |
---|---|---|
id | Integer | The Id of the joke, passed in the URL |
Success-Response:
7
Name | Type | Description |
---|---|---|
joke | json | The Updated Joke |
Error-Response:
{
"message": "YOU SHALL NOT PASS"
}
Error-Response:
{
"message": "Your DAD Joke was not found"
}
Error-Response:
{
"message": "You may only DELETE your own jokes"
}
Get All Public and Private Jokes in the Database
GET /api/jokes
Success-Response:
[
{
"id": 1,
"joke": "Today, my son asked \"Can I have a book mark?\" and I burst into tears.",
"punchline": "11 years old and he still doesn't know my name is Brian",
"created_by": 1,
"privateJoke": false,
"created_at": "2019-11-18T00:51:52.515Z",
"updated_at": "2019-11-18T00:51:52.515Z"
},
{
"id": 2,
"joke": "My wife is really mad at the fact that I have no sense of direction.",
"punchline": "So I packed up my stuff and right.",
"created_by": 2,
"privateJoke": false,
"created_at": "2019-11-18T00:51:52.515Z",
"updated_at": "2019-11-18T00:51:52.515Z"
},
{
"id": 3,
"joke": "How do you make holy water?",
"punchline": "You boil the hell out of it.",
"created_by": 1,
"privateJoke": false,
"created_at": "2019-11-18T00:51:52.515Z",
"updated_at": "2019-11-18T00:51:52.515Z"
},
]
Name | Type | Description |
---|---|---|
AllJokes | json[] | All the Public and Private Jokes |
Error-Response:
{
"message": "YOU SHALL NOT PASS"
}
Get All Public Jokes in the Database
GET /api/jokes/public
Success-Response:
[
{
"id": 1,
"joke": "Today, my son asked \"Can I have a book mark?\" and I burst into tears.",
"punchline": "11 years old and he still doesn't know my name is Brian",
"created_by": 1,
"privateJoke": false,
"created_at": "2019-11-18T00:51:52.515Z",
"updated_at": "2019-11-18T00:51:52.515Z"
},
{
"id": 2,
"joke": "My wife is really mad at the fact that I have no sense of direction.",
"punchline": "So I packed up my stuff and right.",
"created_by": 2,
"privateJoke": false,
"created_at": "2019-11-18T00:51:52.515Z",
"updated_at": "2019-11-18T00:51:52.515Z"
},
{
"id": 3,
"joke": "How do you make holy water?",
"punchline": "You boil the hell out of it.",
"created_by": 1,
"privateJoke": false,
"created_at": "2019-11-18T00:51:52.515Z",
"updated_at": "2019-11-18T00:51:52.515Z"
},
]
Name | Type | Description |
---|---|---|
PublicJokes | json[] | All the Public Jokes |
Add Joke To the Database
POST /api/jokes
Name | Type | Description |
---|---|---|
joke | String | The joke. |
punchline | String | The punchline of the Joke |
privateJoke | Boolean | Is the Joke Private? |
(json) Sample-Request:
{
"joke": "Why did the developer cross the road?",
"punchline": "The code was cleaner on the other side.",
"privateJoke": true
}
Success-Response:
{
"id": 7,
"joke": "Why did the developer cross the road?",
"punchline": "The code was cleaner on the other side.",
"created_by": 5,
"privateJoke": true,
"created_at": "2019-11-18T01:58:29.354Z",
"updated_at": "2019-11-18T01:58:29.354Z"
}
Name | Type | Description |
---|---|---|
Joke | json | The newly created Joke |
Error-Response:
{
"message": "YOU SHALL NOT PASS"
}
Update the Joke with the Provided Id
PUT /api/jokes/:id
Name | Type | Description |
---|---|---|
id | Integer | The Id of the joke, passed in the URL |
joke | String | The joke. |
punchline | String | The punchline of the Joke |
privateJoke | Boolean | Is the Joke Private? |
(json) Sample-Request:
{
"privateJoke": false
}
Success-Response:
{
"id": 7,
"joke": "Why did the developer cross the road?",
"punchline": "The code was cleaner on the other side.",
"created_by": 5,
"privateJoke": false,
"created_at": "2019-11-18T01:58:29.354Z",
"updated_at": "2019-11-18T01:58:29.354Z"
}
Name | Type | Description |
---|---|---|
joke | json | The Updated Joke |
Error-Response:
{
"message": "YOU SHALL NOT PASS"
}
Error-Response:
{
"message": "Your DAD Joke was not found"
}
Error-Response:
{
"message": "You may only EDIT your own jokes"
}
Delete's the User based on the provided token
DELETE /api/user
Success-Response:
6
Name | Type | Description |
---|---|---|
Return | json | the ID of the User Deleted |
Error-Response:
{
"message": "YOU SHALL NOT PASS"
}
Updates the User with provided information
PUT /api/user
Name | Type | Description |
---|---|---|
String | The User's Email |
|
username | String | The User's Username |
password | String | The User's Password |
(json) Sample-Request:
{
"username": "johndoe2",
}
Success-Response:
{
"id": 6,
"email": "john@doe.com",
"username": "johndoe2",
"created_at": "2019-11-18T20:52:38.944Z",
"updated_at": "2019-11-18T20:52:38.944Z"
}
Name | Type | Description |
---|---|---|
user | json | The Updated User |
Error-Response:
{
"message": "YOU SHALL NOT PASS"
}