Created
March 30, 2016 20:23
-
-
Save donny-dont/7f65c4ecfc4c10a61b0d9d55ae88271d to your computer and use it in GitHub Desktop.
Padding as a Dart RPC service
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
library string_pad.api; | |
import 'dart:async'; | |
import 'dart:io'; | |
import 'package:rpc/rpc.dart'; | |
class PaddingResponse { | |
String result; | |
} | |
@ApiClass( | |
name: 'pad', | |
version: 'v1', | |
description: 'Padding all the strings' | |
) | |
class Api { | |
Api(); | |
@ApiMethod(method: 'GET', path: 'left/{width}') | |
PaddingResponse left(int width, {String str, String ch}) { | |
str ??= ''; | |
ch ??= ' '; | |
return new PaddingResponse() | |
..result = str.padLeft(width, ch); | |
} | |
@ApiMethod(method: 'GET', path: 'right/{width}') | |
PaddingResponse right(int width, {String str, String ch}) { | |
str ??= ''; | |
ch ??= ' '; | |
return new PaddingResponse() | |
..result = str.padRight(width, ch); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment