cfpb / regulations-site

(DEPRECATED) Web interface for viewing U.S. federal regulations and other regulatory information
Other
28 stars 43 forks source link

Pull from regulations-core with Python, not HTTP #845

Closed chosak closed 6 years ago

chosak commented 6 years ago

This change makes it possible for regulations-site to pull content from a regulations-core API running in the same Django instance by directly making Python calls instead of using HTTP requests.

By defining the Django setting EREGS_REGCORE_URLS and setting it to the path to your regulations-core URLconf (likely regcore.urls), the API will, instead of using HTTP to make requests, just call the Django views directly.

When running in the same Django installation as regulations-core this saves time and reduces load on the web server.

If this setting is not defined then behavior falls back to the current method of using HTTP requests based on the EREGS_API_BASE environment variable.

The best way to test this in action is to observe that if you run the Django debug server with this setting, you won't see any requests to the regcore API when making regsite requests.

I've added several unit tests that attempt to cover this change. Behavior should be similar to the current HTTP-based approach. If the Django view returns a 404 or raises an Http404 then the API returns None. If the view raises an exception, then the API will pass that along. Otherwise, the view just passes back the JSON content of the regcore view response as if it had been retrieved via HTTP.