From 6052405eb7ec8d7209fc3e3c2e43fe6924c95e59 Mon Sep 17 00:00:00 2001 From: Jeremy Stretch Date: Wed, 11 Oct 2017 16:41:16 -0400 Subject: [PATCH] Added info about API _choices endpoints --- docs/api/overview.md | 39 +++++++++++++++++++++++++++++++++++---- 1 file changed, 35 insertions(+), 4 deletions(-) diff --git a/docs/api/overview.md b/docs/api/overview.md index 39a4109f9..db9c1de4d 100644 --- a/docs/api/overview.md +++ b/docs/api/overview.md @@ -88,10 +88,10 @@ The base serializer is used to represent the default view of a model. This inclu "vid": 101, "name": "Users-Floor1", "tenant": null, - "status": [ - 1, - "Active" - ], + "status": { + "value": 1, + "label": "Active" + }, "role": { "id": 9, "url": "http://localhost:8000/api/ipam/roles/9/", @@ -122,6 +122,37 @@ When a base serializer includes one or more nested serializers, the hierarchical } ``` +## Static Choice Fields + +Some model fields, such as the `status` field in the above example, utilize static integers corresponding to static choices. The available choices can be retrieved from the read-only `_choices` endpoint within each app. A specific `model:field` tuple may optionally be specified in the URL. + +Each choice includes a human-friendly label and its corresponding numeric value. For example, `GET /api/ipam/_choices/prefix:status/` will return: + +``` +[ + { + "value": 0, + "label": "Container" + }, + { + "value": 1, + "label": "Active" + }, + { + "value": 2, + "label": "Reserved" + }, + { + "value": 3, + "label": "Deprecated" + } +] +``` + +Thus, to set a prefix's status to "Reserved," it would be assigned the integer `2`. + +A request for `GET /api/ipam/_choices/` will return choices for _all_ fields belonging to models within the IPAM app. + # Pagination API responses which contain a list of objects (for example, a request to `/api/dcim/devices/`) will be paginated to avoid unnecessary overhead. The root JSON object will contain the following attributes: