-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1849 from get10101/chore/access-rust-api-from-webapp
feat: Add version endpoint
- Loading branch information
Showing
9 changed files
with
86 additions
and
5 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import 'package:http/http.dart' as http; | ||
import 'dart:convert'; | ||
|
||
class Version { | ||
final String version; | ||
|
||
const Version({required this.version}); | ||
|
||
factory Version.fromJson(Map<String, dynamic> json) { | ||
return switch (json) { | ||
{ | ||
'version': String version, | ||
} => | ||
Version(version: version), | ||
_ => throw const FormatException('Failed to load version.'), | ||
}; | ||
} | ||
} | ||
|
||
class VersionService { | ||
const VersionService(); | ||
|
||
Future<String> fetchVersion() async { | ||
// TODO(holzeis): this should come from the config | ||
const port = "3001"; | ||
const host = "localhost"; | ||
|
||
final response = await http.get(Uri.http('$host:$port', '/api/version')); | ||
|
||
if (response.statusCode == 200) { | ||
return Version.fromJson(jsonDecode(response.body) as Map<String, dynamic>).version; | ||
} else { | ||
return 'unknown'; | ||
} | ||
} | ||
} |
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
use axum::Json; | ||
use serde::Serialize; | ||
|
||
#[derive(Serialize)] | ||
pub struct Version { | ||
version: String, | ||
} | ||
|
||
pub async fn version() -> Json<Version> { | ||
Json(Version { | ||
version: env!("CARGO_PKG_VERSION").to_string(), | ||
}) | ||
} |
This file contains 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