Skip to content

Instantly share code, notes, and snippets.

@donny-dont
Created March 30, 2016 20:23
Show Gist options
  • Save donny-dont/7f65c4ecfc4c10a61b0d9d55ae88271d to your computer and use it in GitHub Desktop.
Save donny-dont/7f65c4ecfc4c10a61b0d9d55ae88271d to your computer and use it in GitHub Desktop.
Padding as a Dart RPC service
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