mozilla / mig

Distributed & real time digital forensics at the speed of the cloud
http://mig.mozilla.org/
Mozilla Public License 2.0
1.21k stars 235 forks source link

Implement API endpoint for documentation retrieval #443

Open arcrose opened 6 years ago

arcrose commented 6 years ago

Dependent on #442.

Ideally, what we'd like (to start) are data structures representing the request and response data types for each of the endpoints we'll support. Each structure may implement some interface to provide self-documentation that can be aggregated and served as JSON.

The following example sketches this approach:

type SelfDocumenting interface {
    Documentation() APIDocumentation
}

type APIDocumentation struct {
  Method string `json:"method"`
  Route string `json:"route"`
  // ... 
}

type ReqActionStatus struct {
  ActionID string
}

func (req ReqActionStatus) Documentation() APIDocumentation {
  return APIDocumentation {
    Method: "GET",
    Route: "/v1/actions/:id/status",
    // ...
  }
}

The above could be expanded upon to include something like an Endpoint struct containing empty instances of a request and response type, so that we can start composing these structs to get complete documentation for each endpoint. Serving this information would then simply be a matter of constructing a big nested collection of APIDocumentations, encoding that to JSON, and serving it to the user.