Skip to content
This repository has been archived by the owner on Dec 8, 2017. It is now read-only.

[WIP] Add /api/ endpoint #16

Closed
wants to merge 1 commit into from
Closed

[WIP] Add /api/ endpoint #16

wants to merge 1 commit into from

Conversation

toolness
Copy link
Contributor

This attempts to add a Django REST framework-powered API at /api/.

To do:

  • Consider exposing Client endpoint.
  • Figure out how we want to expose the related Client for a Project in the /projects/ endpoint. For instance, do we want to embed the information inside each project, or do we want it to be a primary key that needs to be looked up at a /clients/{pk} endpoint?
  • Figure out how we want to represent our model fields that have choices options. Currently, for example, Project.status is an integer that corresponds to tentative/active/paused/complete. But we might instead want this to be an actual string describing the choice.
  • Figure out what fields we want to expose on Project. For example, do we want to expose mb_number? Alternatively, do we want to expose only a strict subset of fields by default, but show additional fields if they're specified as querystring arguments?
  • Add CORS support for the API.

@@ -68,3 +70,10 @@

STATICFILES_DIRS = ()
STATICFILES_STORAGE = 'whitenoise.django.GzipManifestStaticFilesStorage'

REST_FRAMEWORK = {
'UNICODE_JSON': False,
Copy link
Contributor Author

@toolness toolness May 16, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a bit annoying. Basically, even though our API standards say we should use UTF-8 and set our Content-Type header to Content-Type: application/json; charset=utf-8, what's really weird is that doing so actually goes against the JSON spec.

The creator of Django REST Framework sides with the spec and makes it very difficult/impossible to add a charset parameter to the Content-Type encoding.

So there's a lot of contention over whether or not it's ok to specify a charset parameter for JSON content, and personally I think the easiest solution is to avoid the debate altogether by ensuring that your output is ASCII with unicode escape sequences in them. This does result in larger payloads and is especially inefficient if our payloads contain lots of non-ASCII characters, but it's the most compatible across clients.

Anyways, the UNICODE_JSON parameter above makes that happen.

Update: just filed 18F/api-standards#68 to address this in our standards.

@brendansudol
Copy link
Contributor

per discussion (over video), closing this for now until we have a specific api client and use case -- good call, @toolness!

@toolness toolness mentioned this pull request Jun 7, 2016
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants