-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcalc_api.pl
More file actions
executable file
·36 lines (26 loc) · 810 Bytes
/
Copy pathcalc_api.pl
File metadata and controls
executable file
·36 lines (26 loc) · 810 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#!/usr/bin/env perl
# Main driver for the Web API.
# It uses json as a response format
# Each end-point only takes 1 or two parameters, but most operations could easily be enhanced
# to receive multiple parameters
use CalcCore;
use CalcResult;
use Dancer;
use Dancer::Plugin::REST;
get '/factorial/:name' => sub {
return factorial(params->{name})->json();
};
get '/add/:num_a/:num_b' => sub {
return add(params->{num_a}, params->{num_b})->json();
};
get '/divide/:num_a/:num_b' => sub {
return divide(params->{num_a}, params->{num_b})->json();
};
get '/substract/:num_a/:num_b' => sub {
return substract(params->{num_a}, params->{num_b})->json();
};
get '/multiply/:num_a/:num_b' => sub {
return multiply(params->{num_a}, params->{num_b})->json();
};
# start the webserver
dance;