A Habitat represents a physical zone or enclosure within the park where animals live. Each habitat belongs to a Section — the top-level organizational area of the park — and tracks how many animals it currently houses.
All write operations (POST, PUT, DELETE) require authentication via IsAuthenticatedAndRole. GET endpoints return data publicly.
Endpoints
List habitats
Returns all habitats ordered alphabetically by name.
curl --request GET \
--url https://api.parquemarino.org/api/habitats/
[
{
"id" : 1 ,
"name" : "Laguna Tropical" ,
"nums_animals" : 14 ,
"description" : "Warm shallow reef exhibit with coral formations." ,
"section" : 2
},
{
"id" : 2 ,
"name" : "Océano Abierto" ,
"nums_animals" : 6 ,
"description" : "Deep-water pelagic zone exhibit." ,
"section" : 1
}
]
Response fields
Unique identifier for the habitat.
Name of the habitat. Maximum 30 characters. Must be unique across all habitats. Records are ordered alphabetically by this field.
Current number of animals housed in this habitat. Must be a positive integer.
Short description of the habitat. Maximum 100 characters.
Foreign key referencing the parent Sections record. Deleting a section cascades to its habitats. Unique identifier for the section.
Name of the section. Maximum 30 characters. Must be unique.
Create habitat
Requires admin authentication.
Name of the habitat. Maximum 30 characters. Must be unique.
Initial animal count for this habitat. Must be zero or greater.
Short description. Maximum 100 characters.
ID of the parent section.
curl --request POST \
--url https://api.parquemarino.org/api/habitats/create/ \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '{
"name": "Zona Manglares",
"nums_animals": 8,
"description": "Brackish mangrove estuary habitat.",
"section": 1
}'
{
"id" : 5 ,
"name" : "Zona Manglares" ,
"nums_animals" : 8 ,
"description" : "Brackish mangrove estuary habitat." ,
"section" : 1
}
Retrieve habitat
Primary key of the habitat.
curl --request GET \
--url https://api.parquemarino.org/api/habitats/1/
{
"id" : 1 ,
"name" : "Laguna Tropical" ,
"nums_animals" : 14 ,
"description" : "Warm shallow reef exhibit with coral formations." ,
"section" : 2
}
Update habitat
Requires admin authentication. Only PUT is supported; PATCH is not exposed.
Primary key of the habitat to update.
Updated habitat name. Maximum 30 characters.
Updated description. Maximum 100 characters.
Updated parent section ID.
curl --request PUT \
--url https://api.parquemarino.org/api/habitats/1/update/ \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '{
"name": "Laguna Tropical",
"nums_animals": 16,
"description": "Warm shallow reef exhibit with coral formations.",
"section": 2
}'
{
"id" : 1 ,
"name" : "Laguna Tropical" ,
"nums_animals" : 16 ,
"description" : "Warm shallow reef exhibit with coral formations." ,
"section" : 2
}
Delete habitat
Deleting a habitat cascades to all animals that reference it. This action cannot be undone.
Requires admin authentication.
Primary key of the habitat to delete.
curl --request DELETE \
--url https://api.parquemarino.org/api/habitats/1/delete/ \
--header 'Authorization: Bearer <token>'
Relationship to species
Habitats do not directly reference species in the data model. The relationship is established through the Animals resource: each animal belongs to one habitat and one species. To find all species present in a given habitat, query /api/animals/?habitat={id} and inspect the species field on each result.
# Find all animals (and their species) in habitat 1
curl 'https://api.parquemarino.org/api/animals/?habitat=1'