Extension of a Backend Project for Lambda School's Build Week, deployed Link is https://key-conservation-app.herokuapp.com/
POST /api/register
Name | Type | Description |
---|---|---|
username | String | The new users username Required Unique |
String | The new users email Required Unique |
|
password | String | The new users password Required |
user_type | String | The user type, "organization", "supporter", or "admin" Required |
org_id | Integer | The users organization, required if user_type is "organization" |
{
"message": "Welcome, <username>",
"user": {
"id": 1,
"username": "test",
"email": "test@test.biz",
"user_type": "organization",
"org_id": 1
},
"token": "somelongtokenstring"
}
POST /api/login
Name | Type | Description |
---|---|---|
username | String | Username of the user Required |
password | String | Password of the user Required |
{
"message": "Welcome, <username>",
"user": {
"id": 1,
"username": "test",
"email": "test@test.biz",
"user_type": "organization",
"org_id": 1
},
"token": "somelongtokenstring"
}
Invalid username
{
"message": "Username not found"
}
Invalid password
{
"message": "Invalid password"
}
Missing username
{
"message": "Username is required."
}
Missing password
{
"message": "Password is required."
}
GET /api/users
user_type must be "admin" Returns full list of users
[
{
"id": 1,
"username": "test",
"email": "test@test.biz",
"user_type": "organization",
"org_id": 1
},
...
]
Invalid user type ("supporter" or "organization")
{
"message": "Admin access only."
}
No authorization token
{
"message": "User not authenticated. Please log in and try again."
}
GET /api/users/:id
user_type must be "admin" or user_id must match request id Returns specified user object
{
"id": 1,
"username": "test",
"email": "test@test.biz",
"user_type": "organization",
"org_id": 1
}
No user with specified id
{
"message": "User not found"
}
No authorization token
{
"message": "User not authenticated. Please log in and try again."
}
User_type is not "admin" or user_id does not match request id
{
"message": "Access denied."
}
PUT /api/users/:id
Name | Type | Description |
---|---|---|
username | String | The new users username Required Unique |
String | The new users email Required Unique |
|
password | String | The new users password Required |
user_type | String | The user type, "organization", "supporter", or "admin" Required |
org_id | Integer | The users organization, required if user_type is "organization" |
user_type must be "admin" or user_id must match request id Returns updated user object
{
"id": 1,
"username": "test",
"email": "test@test.biz",
"user_type": "organization",
"org_id": 1
}
No user with specified id
{
"message": "User not found"
}
No authorization token
{
"message": "User not authenticated. Please log in and try again."
}
User_type is not "admin" or user_id does not match request id
{
"message": "Access denied."
}
DELETE /api/users/:id
user_type must be "admin"
Returns status 204 (no content)
No user with specified id
{
"message": "User not found"
}
No authorization token
{
"message": "User not authenticated. Please log in and try again."
}
User_type is not "admin"
{
"message": "Admin access only."
}
POST /api/users/:id/favorites
user_type must be "supporter", logged in user_id must match request id
returns user data and full list of favorite campaigns
{
"id": 1,
"username": "test",
"email": "test@test.biz",
"user_type": "organization",
"org_id": null
"favorite_campaigns": [
{
"id": 1,
"title": "Conserving migrating raptors in western Georgia",
"description": "The illegal trapping and sale of birds for falconry, a traditional practice in Georgia, pose a threat to raptor species. It is estimated that 200,000 birds are trapped each year with 5,000 being smuggled out of the country. For some species, birds regarded as low quality are also killed to remove them from populations. The illegal and unsustainable trade in raptors is significantly affecting a number of species including the saker falcon, Eurasian sparrowhawk, northern goshawk and peregrine falcon, which are targeted for falconry. FFI is seeking to address these threats by working closely with falconers’ associations and in cooperation with relevant government agencies to regulate the practice of falconry and to stop illegal international trade in birds of prey.",
"photo_url": "https://cms.fauna-flora.org/wp-content/uploads/2017/11/conserving-migrating-raptors-in-western-georgia-2000x1200.jpg",
"location": "Georgia, Eurasia",
"species": "saker falcon, Eurasian sparrowhawk, northern goshawk and peregrine falcon",
"urgency_level": 6,
"funding_goal": 10000,
"deadline": "2020-06-01T00:00:00.000Z",
"org_id": 1,
"org_name": "Fauna and Flora International"
},
...
]
}
No user with specified id
{
"message": "User not found"
}
No authorization token
{
"message": "User not authenticated. Please log in and try again."
}
User_type is not "supporter", or user_id does not match request id
{
"message": "Access denied."
}
POST /api/users/:id/favorites
Name | Type | Description |
---|---|---|
campaign_id | Integer | Id of the campaign to add to the user's favorites list Required |
user_type must be "supporter", logged in user_id must match request id
{
"user_id": 1,
"campaign_id": 2
}
No user with specified id
{
"message": "User not found"
}
No authorization token
{
"message": "User not authenticated. Please log in and try again."
}
User_type is not "supporter", or user_id does not match request id
{
"message": "Access denied."
}
POST /api/users/:id/favorites/:campaignId
user_type must be "supporter", logged in user_id must match request id
Returns status 204 (no content)
No user with specified id
{
"message": "User not found"
}
No authorization token
{
"message": "User not authenticated. Please log in and try again."
}
User_type is not "supporter", or user_id does not match request id
{
"message": "Access denied."
}
GET /api/campaigns
Returns full list of campaigns (no token required)
[
{
"id": 1,
"title": "Conserving migrating raptors in western Georgia",
"description": "The illegal trapping and sale of birds for falconry, a traditional practice in Georgia, pose a threat to raptor species. It is estimated that 200,000 birds are trapped each year with 5,000 being smuggled out of the country. For some species, birds regarded as low quality are also killed to remove them from populations. The illegal and unsustainable trade in raptors is significantly affecting a number of species including the saker falcon, Eurasian sparrowhawk, northern goshawk and peregrine falcon, which are targeted for falconry. FFI is seeking to address these threats by working closely with falconers’ associations and in cooperation with relevant government agencies to regulate the practice of falconry and to stop illegal international trade in birds of prey.",
"photo_url": "https://cms.fauna-flora.org/wp-content/uploads/2017/11/conserving-migrating-raptors-in-western-georgia-2000x1200.jpg",
"location": "Georgia, Eurasia",
"species": "saker falcon, Eurasian sparrowhawk, northern goshawk and peregrine falcon",
"urgency_level": 6,
"funding_goal": 10000,
"deadline": "2020-06-01T00:00:00.000Z",
"org_id": 1,
"org_name": "Fauna and Flora International"
},
...
]
GET /api/campaigns/:id
Returns specified campaign object (no token required)
{
"id": 1,
"title": "Conserving migrating raptors in western Georgia",
"description": "The illegal trapping and sale of birds for falconry, a traditional practice in Georgia, pose a threat to raptor species. It is estimated that 200,000 birds are trapped each year with 5,000 being smuggled out of the country. For some species, birds regarded as low quality are also killed to remove them from populations. The illegal and unsustainable trade in raptors is significantly affecting a number of species including the saker falcon, Eurasian sparrowhawk, northern goshawk and peregrine falcon, which are targeted for falconry. FFI is seeking to address these threats by working closely with falconers’ associations and in cooperation with relevant government agencies to regulate the practice of falconry and to stop illegal international trade in birds of prey.",
"photo_url": "https://cms.fauna-flora.org/wp-content/uploads/2017/11/conserving-migrating-raptors-in-western-georgia-2000x1200.jpg",
"location": "Georgia, Eurasia",
"species": "saker falcon, Eurasian sparrowhawk, northern goshawk and peregrine falcon",
"urgency_level": 6,
"funding_goal": 10000,
"deadline": "2020-06-01T00:00:00.000Z",
"org_id": 1,
"org_name": "Fauna and Flora International"
}
No campaign with specified id
{
"message": "Campaign not found"
}
POST /api/campaigns
Name | Type | Description |
---|---|---|
title | String | Title of the campaign Required |
description | String | Description of the campaign |
photo_url | String | Url for the campaign photo |
location | String | Location of the campaign Required |
species | String | Species of the campaign Required |
urgency_level | Integer | Urgency level of the campaign (1 = low, 10 = high) Required |
funding_goal | Integer | Funding goal of the campaign |
deadline | Date | Deadline of the campaign |
org_id | Integer | The organization id of the logged in user Auto Populated |
Returns new campaign object
{
"id": 1,
"title": "Conserving migrating raptors in western Georgia",
"description": "The illegal trapping and sale of birds for falconry, a traditional practice in Georgia, pose a threat to raptor species. It is estimated that 200,000 birds are trapped each year with 5,000 being smuggled out of the country. For some species, birds regarded as low quality are also killed to remove them from populations. The illegal and unsustainable trade in raptors is significantly affecting a number of species including the saker falcon, Eurasian sparrowhawk, northern goshawk and peregrine falcon, which are targeted for falconry. FFI is seeking to address these threats by working closely with falconers’ associations and in cooperation with relevant government agencies to regulate the practice of falconry and to stop illegal international trade in birds of prey.",
"photo_url": "https://cms.fauna-flora.org/wp-content/uploads/2017/11/conserving-migrating-raptors-in-western-georgia-2000x1200.jpg",
"location": "Georgia, Eurasia",
"species": "saker falcon, Eurasian sparrowhawk, northern goshawk and peregrine falcon",
"urgency_level": 6,
"funding_goal": 10000,
"deadline": "2020-06-01T00:00:00.000Z",
"org_id": 1
}
No authorization token
{
"message": "User not authenticated. Please log in and try again."
}
User_type is "supporter" or "admin"
{
"message": "Access denied."
}
POST /api/campaigns/:id
Name | Type | Description |
---|---|---|
title | String | Title of the campaign Required |
description | String | Description of the campaign |
photo_url | String | Url for the campaign photo |
location | String | Location of the campaign Required |
species | String | Species of the campaign Required |
urgency_level | Integer | Urgency level of the campaign (1 = low, 10 = high) Required |
funding_goal | Integer | Funding goal of the campaign |
deadline | Date | Deadline of the campaign |
org_id | Integer | The organization id of the logged in user Auto Populated |
Returns new campaign object
{
"id": 1,
"title": "Conserving migrating raptors in western Georgia",
"description": "The illegal trapping and sale of birds for falconry, a traditional practice in Georgia, pose a threat to raptor species. It is estimated that 200,000 birds are trapped each year with 5,000 being smuggled out of the country. For some species, birds regarded as low quality are also killed to remove them from populations. The illegal and unsustainable trade in raptors is significantly affecting a number of species including the saker falcon, Eurasian sparrowhawk, northern goshawk and peregrine falcon, which are targeted for falconry. FFI is seeking to address these threats by working closely with falconers’ associations and in cooperation with relevant government agencies to regulate the practice of falconry and to stop illegal international trade in birds of prey.",
"photo_url": "https://cms.fauna-flora.org/wp-content/uploads/2017/11/conserving-migrating-raptors-in-western-georgia-2000x1200.jpg",
"location": "Georgia, Eurasia",
"species": "saker falcon, Eurasian sparrowhawk, northern goshawk and peregrine falcon",
"urgency_level": 6,
"funding_goal": 10000,
"deadline": "2020-06-01T00:00:00.000Z",
"org_id": 1
}
No authorization token
{
"message": "User not authenticated. Please log in and try again."
}
User_type is "supporter" or "admin"
{
"message": "Access denied."
}
No campaign with specified id
{
"message": "Campaign not found"
}
DELETE /api/campaigns/:id
Returns status 204 (no content)
No authorization token
{
"message": "User not authenticated. Please log in and try again."
}
User_type is "supporter" or "admin"
{
"message": "Access denied."
}
No campaign with specified id
{
"message": "Campaign not found"
}
GET /api/organizations
Returns full list of organizations (no token required)
[
{
"id": 1,
"name": "Fauna and Flora International"
},
{
"id": 2,
"name": "Australian Wildlife Society"
},
{
"id": 3,
"name": "African Wildlife Foundation"
},
{
"id": 4,
"name": "Panthera"
}
]
GET /api/organizations/:id
Returns all campaigns from the specified organization (no token required)
[
{
"id": 1,
"title": "Conserving migrating raptors in western Georgia",
"description": "The illegal trapping and sale of birds for falconry, a traditional practice in Georgia, pose a threat to raptor species. It is estimated that 200,000 birds are trapped each year with 5,000 being smuggled out of the country. For some species, birds regarded as low quality are also killed to remove them from populations. The illegal and unsustainable trade in raptors is significantly affecting a number of species including the saker falcon, Eurasian sparrowhawk, northern goshawk and peregrine falcon, which are targeted for falconry. FFI is seeking to address these threats by working closely with falconers’ associations and in cooperation with relevant government agencies to regulate the practice of falconry and to stop illegal international trade in birds of prey.",
"photo_url": "https://cms.fauna-flora.org/wp-content/uploads/2017/11/conserving-migrating-raptors-in-western-georgia-2000x1200.jpg",
"location": "Georgia, Eurasia",
"species": "saker falcon, Eurasian sparrowhawk, northern goshawk and peregrine falcon",
"urgency_level": 6,
"funding_goal": 10000,
"deadline": "2020-06-01T00:00:00.000Z",
"org_id": 1,
"org_name": "Fauna and Flora International"
},
...
]
No organization with specified id
{
"message": "Organization not found"
}
POST /api/organizations
Name | Type | Description |
---|---|---|
name | String | Title of the organization Required |
Returns new organization object
{
"id": 1,
"name": "Fauna and Flora International"
}
No authorization token
{
"message": "User not authenticated. Please log in and try again."
}
User_type is "supporter" or "organization"
{
"message": "Admin access only."
}
POST /api/organizations/:id
Name | Type | Description |
---|---|---|
name | String | Title of the organization Required |
Returns updated organization object
{
"id": 1,
"name": "Fauna and Flora International"
}
No authorization token
{
"message": "User not authenticated. Please log in and try again."
}
User_type is "supporter" or "organization"
{
"message": "Admin access only."
}
No organization with specified id
{
"message": "Organization not found"
}
DELETE /api/organizations/:id
Returns status 204 (no content)
No authorization token
{
"message": "User not authenticated. Please log in and try again."
}
User_type is "supporter" or "organization"
{
"message": "Admin access only."
}
No organization with specified id
{
"message": "Organization not found"
}