Created
March 5, 2015 16:52
-
-
Save jmandzik/d50939dde3d1af6f51a7 to your computer and use it in GitHub Desktop.
Calibrate, Hapi, metadata
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // I'm coming from a monolithic PHP app (sound familiar, lol), who's routes are | |
| // structured like /Controller/method/{id}. We add some timing instrumentation that gets | |
| // added to the reponse before its sent back to the browser. | |
| // This is roughly what we output today | |
| { | |
| id: "a81d99414a", | |
| time-load: "0.0012", // constructor timing | |
| time-auth: "0.3960", // time to authenticate | |
| time-authz: "0.0054", // time to authorize | |
| time-method: "0.0081", // method execution (analagous to Hapi handler timing(?)) | |
| time-total: "0.4157", // Time from earliest entry to right before reponse is sent | |
| date: "2015-03-05 11:41:39", | |
| url: "http://host:1234/path/to/resource", | |
| server: "localhost", | |
| client: "10.10.7.110", | |
| results: [] // The actual data from the call | |
| } | |
| // Reimaging this as a Calibrated response: | |
| { | |
| statusCode: 200, | |
| data: { | |
| // The actual data from the call | |
| }, | |
| meta: { | |
| id: "a81d99414a", | |
| time-load: "0.0012", // constructor timing | |
| time-auth: "0.3960", // time to authenticate | |
| time-authz: "0.0054", // time to authorize | |
| time-method: "0.0081", // method execution (analagous to Hapi handler timing(?)) | |
| time-total: "0.4157", // Time from earliest entry to right before reponse is sent | |
| date: "2015-03-05 11:41:39", | |
| url: "http://host:1234/path/to/resource", | |
| server: "localhost", | |
| client: "10.10.7.110", | |
| } | |
| } | |
| // I'm still learning Hapi... not sure the best way to: | |
| // 1) inject those timing hooks | |
| // 2) get that meta data into all calibrated responses with a minimum of boilerplate. | |
| // Since this is just an API, I'd even prefer if the reply.calibrate() was able to somehow just be reply() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment