Aller au contenu principal

Communes

Les communes sont le troisième niveau de la hiérarchie géographique, rattachées à un département.

Hiérarchie géographique

Région → Secteur → Commune → Localité
^^^^^^^^

GET /api/communes

Récupère la liste des communes.

Endpoint

GET /api/communes

Headers

HeaderValeurRequis
AuthorizationBearer {token}Oui

Réponse succès

Code: 200 OK

{
"@context": "/api/contexts/Commune",
"@id": "/api/communes",
"@type": "hydra:Collection",
"hydra:totalItems": 552,
"hydra:member": [
{
"@id": "/api/communes/bb0e8400-e29b-41d4-a716-446655440001",
"@type": "Commune",
"id": "bb0e8400-e29b-41d4-a716-446655440001",
"nom": "Commune de Dakar",
"code": "COM-DK-001",
"departement": {
"@id": "/api/departements/cc0e8400-e29b-41d4-a716-446655440001",
"nom": "Département de Dakar"
}
},
{
"@id": "/api/communes/bb0e8400-e29b-41d4-a716-446655440002",
"@type": "Commune",
"id": "bb0e8400-e29b-41d4-a716-446655440002",
"nom": "Commune de Pikine",
"code": "COM-DK-002",
"departement": {
"@id": "/api/departements/cc0e8400-e29b-41d4-a716-446655440002",
"nom": "Département de Pikine"
}
}
],
"hydra:view": {
"@id": "/api/communes?page=1",
"hydra:first": "/api/communes?page=1",
"hydra:last": "/api/communes?page=19"
}
}

GET /api/communes/{id}

Récupère une commune par son identifiant.

Endpoint

GET /api/communes/{id}

Réponse succès

Code: 200 OK

{
"@context": "/api/contexts/Commune",
"@id": "/api/communes/bb0e8400-e29b-41d4-a716-446655440001",
"@type": "Commune",
"id": "bb0e8400-e29b-41d4-a716-446655440001",
"nom": "Commune de Dakar",
"code": "COM-DK-001",
"departement": {
"@id": "/api/departements/cc0e8400-e29b-41d4-a716-446655440001",
"@type": "Departement",
"nom": "Département de Dakar"
}
}

Exemples

cURL

# Liste des communes
curl https://sig.ucp-pch.org/api/communes \
-H "Authorization: Bearer TOKEN"

# Commune par ID
curl https://sig.ucp-pch.org/api/communes/bb0e8400-e29b-41d4-a716-446655440001 \
-H "Authorization: Bearer TOKEN"

JavaScript

const getCommunes = async () => {
const response = await fetch(
'https://sig.ucp-pch.org/api/communes',
{
headers: {
'Authorization': `Bearer ${localStorage.getItem('token')}`
}
}
);
return response.json();
};

// Utilisation
const communes = await getCommunes();
console.log(`${communes['hydra:totalItems']} communes`);

communes['hydra:member'].forEach(commune => {
console.log(`${commune.nom} - ${commune.departement?.nom || 'N/A'}`);
});

Python

import requests

def get_communes(token):
response = requests.get(
'https://sig.ucp-pch.org/api/communes',
headers={'Authorization': f'Bearer {token}'}
)
return response.json()

# Utilisation
communes = get_communes(token)
print(f"Total: {communes['hydra:totalItems']} communes")

for commune in communes['hydra:member']:
dept = commune.get('departement', {}).get('nom', 'N/A')
print(f"- {commune['nom']} ({dept})")

Champs

ChampTypeDescription
idUUIDIdentifiant unique
nomstringNom de la commune
codestringCode de la commune
departementobjectDépartement parent (nullable)

Notes

  • Les communes sont rattachées à un département (optionnel)
  • Utilisées comme référence pour les ménages
  • La création/modification nécessite le rôle ADMIN