Page MenuHomeDevCentral

Provide an API module
ClosedPublic

Authored by dereckson on Sep 4 2018, 14:57.
Tags
None
Referenced Files
F3605358: D1663.diff
Sun, Sep 29, 20:25
F3601802: D1663.diff
Sat, Sep 28, 21:39
Unknown Object (File)
Fri, Sep 6, 21:54
Unknown Object (File)
Fri, Sep 6, 07:41
Unknown Object (File)
Thu, Sep 5, 10:09
Unknown Object (File)
Thu, Sep 5, 09:51
Unknown Object (File)
Mon, Sep 2, 08:32
Unknown Object (File)
Aug 27 2024, 04:05
Subscribers
None

Details

Summary

API replies in REST API tend to be:

  • JSON representations of objects from a datasource, or a calculation
  • Failures with relevant status code (400, 403, 404, 409, 500, etc.)

This module provides traits to consume values and get such API response.

It provides trait implementation for Diesel QueryResult, so you can do
something like this:

pub fn get_player(connection: DatabaseConnection, name: String) -> ApiJsonResponse<Player> {
    players
        .filter(username.eq(&name))
        .first::<Player>(&*connection)
        .into_json_response()
}

This will produce a JSON representation when the result is found,
a 404 error when no result is found, a 500 error if there is a database issue.

Diff Detail

Repository
rLF Limiting Factor
Lint
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

dereckson created this revision.
This revision is now accepted and ready to land.Sep 4 2018, 14:58
This revision was automatically updated to reflect the committed changes.