Skip to main content
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

id
integer
required
Unique identifier for the habitat.
name
string
required
Name of the habitat. Maximum 30 characters. Must be unique across all habitats. Records are ordered alphabetically by this field.
nums_animals
integer
required
Current number of animals housed in this habitat. Must be a positive integer.
description
string
required
Short description of the habitat. Maximum 100 characters.
section
integer
required
Foreign key referencing the parent Sections record. Deleting a section cascades to its habitats.

Create habitat

Requires admin authentication.
name
string
required
Name of the habitat. Maximum 30 characters. Must be unique.
nums_animals
integer
required
Initial animal count for this habitat. Must be zero or greater.
description
string
required
Short description. Maximum 100 characters.
section
integer
required
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

id
integer
required
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.
id
integer
required
Primary key of the habitat to update.
name
string
required
Updated habitat name. Maximum 30 characters.
nums_animals
integer
required
Updated animal count.
description
string
required
Updated description. Maximum 100 characters.
section
integer
required
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.
id
integer
required
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'

Build docs developers (and LLMs) love