File: Client-API.2gg

package info (click to toggle)
golf 601.4.41-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 2,824 kB
  • sloc: ansic: 20,020; sh: 1,171; makefile: 292
file content (835 lines) | stat: -rw-r--r-- 25,241 bytes parent folder | download
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
.TH GOLF 2gg $VERSION $DATE Development Tools
.SH NAME
Client-API \- Golf documentation (API)
.SH DESCRIPTION
You can use C API client library to connect to Golf:

.RS 4
\[bu]    
The API has only a few functions, and the main one is "gg_cli_request()", which makes a call to the service.

.RE

.RS 4
\[bu]    
There is only a single data type used, which is "gg_cli" and it is used to specify a request and its options, as well as to retrieve results.

.RE

.RS 4
\[bu]    
There is a single include file ("gcli.h"). 

.RE

.RS 4
\[bu]    
When building your client executable, you can either specify build flags by using the result of "gg -i" (if you have Golf installed), or use self-contained source files directly.

.RE

.RS 4
\[bu]    
It is MT-safe, so you can use it in multi-threaded applications, such as to make many requests in parallel.
.RE

See Examples section below for detailed examples.

.LP
.B SENDING A REQUEST TO GOLF SERVICE
.LP

The following function is used to make a call using C API:

.RS 4
.EX

int gg_cli_request (gg_cli *req);

.EE
.RE

All input and output is contained in a single variable of type "gg_cli", the pointer to which is passed to "gg_cli_request()" function that sends a request to the service. A variable of type "gg_cli" must be initialized to zero before using it (such as with {0} initialization, "memset()" or "calloc()"), or otherwise some of its members may have random values:

.RS 4
.EX

// Define and initialize request variable
gg_cli req = {0};
// You could also do:
// memset ((char*)&req, 0, sizeof(gg_cli));
\[char46]..
// Set members of 'req' variable (see below)
\[char46]..
// Make a call
int result = gg_cli_request (&req);

.EE
.RE

Type "gg_cli" is defined as (i.e. public members of it):

.RS 4
.EX

typedef struct {
    const char *server; // the IP:port/socket_path to server
    const char *req_method; // request method
    const char *app_path; // application path
    const char *req; // request name
    const char *url_params; // URL params (path+query string)
    const char *content_type; // content type
    int content_len; // content len
    const char *req_body; // request body (i.e. content)
    char **env; // environment to pass to servicde
    int timeout; // timeout for request
    int req_status; // status of request from service
    int data_len; // length of response from service
    int error_len; // length of error from service
    char *errm; // error message when gg_cli_request returns other than GG_OKAY
    gg_cli_out_hook out_hook; // hook to get data output as soon as it arrives
    gg_cli_err_hook err_hook; // hook get error output as soon as it arrives
    gg_cli_done_hook done_hook; // get all data when request is complete
    int thread_id; // custom ID when executing in a multithreaded fashion
    volatile char done; // indicator that the request has completed
    int return_code; // the return code from gg_cli_request()
} gg_cli;

.EE
.RE



.B - Mandatory input

The following members of "gg_cli" type must be supplied in order to make a call to a service:

.RS 4
\[bu]    
"server" represents either a Unix socket or a TCP socket, and is:

.RS 4
\[bu]    
for a Unix socket, a fully qualified name to a Unix socket file used to communicate with the service (for a Golf service, it's "/var/lib/gg/<app name>/sock/sock", where <app name> is the application name), or

.RE

.RS 4
\[bu]    
for a TCP socket, a host name and port name in the form of "<host name>:<port number>", specifying where is the server listening on (for instance "127.0.0.1:2301" if the Golf service is local and runs on TCP port 2301).
.RE


.RE

.RS 4
\[bu]    
"req_method" is a request method, such as "GET", "POST", "PUT", "DELETE" or any other.

.RE

.RS 4
\[bu]    
"app_path" is an application path (see \fBrequest\fP). By default it's "/<application name>". 

.RE

.RS 4
\[bu]    
"req" is a request path, i.e. a request name preceded by a forward slash, as in "/<request name>" (see \fBrequest\fP).
.RE


.B - URL parameters

"url_params" is the URL parameters, meaning input parameters (as path segments and query string, see \fBrequest\fP). URL parameters can be NULL or empty, in which case it is not used.


.B - Request body (content)

"req_body" is the request body, which can be any text or binary data. "content_type" is the content type of request body (for instance "application/json" or "image/jpg"). "content_len" is the length of request body in bytes. A request body is sent only if "content_type" and "req_body" are not NULL and not empty, and if "content_len" is greater than zero.


.B - Passing environment to service

"env" is any environment variables that should be passed along to the service. You can access those in Golf via "environment" clause of \fBget-sys\fP statement. This is an array of strings, where name/value pairs are specified one after the other, and which always must end with NULL. For example, if you want to use variable "REMOTE_USER" with value "John" and variable "MY_VARIABLE" with value "8000", then it might look like this:

.RS 4
.EX

char *env[5];
env[0] = "REMOTE_USER";
env[1] = "John"
env[2] = "MY_VARIABLE";
env[3] = "8000"
env[4] = NULL;

.EE
.RE

Thus, if you are passing N environment variables to the service, you must size "env" as "char*" array with 2*N+1 elements. 

Note that in order to suppress output of HTTP headers from the service, you can include environment variable "GG_SILENT_HEADER" with value "yes"; to let the service control headers output (either by default, with "-z" option of \fBmgrg\fP or with \fBsilent-header\fP) simply omit this environment variable.


.B - Timeout

"timeout" is the number of seconds a call to the service should not exceed. For instance if the remote service is taking too long or if the network connection is too slow, you can limit how long to wait for a reply. If there is no timeout, then "timeout" value should be zero. Note that DNS resolution of the host name (in case you are using a TCP socket) is not counted in timeout. Maximum value for timeout is 86400.

Even if timeout is set to 0, a service call may eventually timeout due to underlying socket and network settings. Note that even if your service call times out, the actual service executing may continue until it's done.

.B - Thread ID

"thread_id" is an integer that you can set and use when your program is multithreaded. By default it's 0. This number is set by you and passed to hooks (your functions called when request is complete or data available). You can use this number to differentiate the data with regards to which thread it belongs to.


.B - Completion indicator and return code

When your program is multithreaded, it may be useful to know when (and if) a request has completed. "done" is set to "true" when a request completes, and "return_code" is the return value from gg_cli_request() (see below for a list). In a single-threaded program, this information is self-evident, but if you are running more than one request at the same time (in different threads), you can use these to check on each request executing in parallel (for instance in a loop in the main thread).

Note that "done" is "true" specifically when all the results of a request are available and the request is about to be completed. In a multithreaded program, it means the thread is very soon to terminate or has already terminated; it does not mean that thread has positively terminated. Use standard "pthread_join()" function to make sure the thread has terminated if that is important to you. 

.LP
.B RETURN VALUE OF GG_CLI_REQUEST()
.LP

The following are possible return values from "gg_cli_request()" (available in "return_code" member of "gg_cli" type):

.RS 4
\[bu]    
GG_OKAY if request succeeded,

.RE

.RS 4
\[bu]    
GG_CLI_ERR_RESOLVE_ADDR if host name for TCP connection cannot be resolved,

.RE

.RS 4
\[bu]    
GG_CLI_ERR_PATH_TOO_LONG if path name of Unix socket is too long,

.RE

.RS 4
\[bu]    
GG_CLI_ERR_SOCKET if cannot create a socket (for instance they are exhausted for the process or system),

.RE

.RS 4
\[bu]    
GG_CLI_ERR_CONNECT if cannot connect to server (TCP or Unix alike),

.RE

.RS 4
\[bu]    
GG_CLI_ERR_SOCK_WRITE if cannot write data to server (for instance if server has encountered an error or is down, or if network connection is no longer available),

.RE

.RS 4
\[bu]    
GG_CLI_ERR_SOCK_READ if cannot read data from server (for instance if server has encountered an error or is down, or if network connection is no longer available),

.RE

.RS 4
\[bu]    
GG_CLI_ERR_PROT_ERR if there is a protocol error, which indicates a protocol issue on either or both sides,

.RE

.RS 4
\[bu]    
GG_CLI_ERR_BAD_VER if either side does not support protocol used by the other,

.RE

.RS 4
\[bu]    
GG_CLI_ERR_SRV if server cannot complete the request,

.RE

.RS 4
\[bu]    
GG_CLI_ERR_UNK if server does not recognize record types used by the client,

.RE

.RS 4
\[bu]    
GG_CLI_ERR_OUT_MEM if client is out of memory,

.RE

.RS 4
\[bu]    
GG_CLI_ERR_ENV_TOO_LONG if the combined length of all environment variables is too long,

.RE

.RS 4
\[bu]    
GG_CLI_ERR_ENV_ODD if the number of supplied environment name/value pairs is incorrect,

.RE

.RS 4
\[bu]    
GG_CLI_ERR_BAD_TIMEOUT if the value for timeout is incorrect,

.RE

.RS 4
\[bu]    
GG_CLI_ERR_TIMEOUT if the request timed out based on "timeout" parameter or otherwise if the underlying Operating System libraries declared their own timeout.
.RE

You can obtain the error message (corresponding to the above return values) in "errm" member of "gg_cli" type.

.LP
.B SERVER REPLY
.LP

The service reply is split in two. One part is the actual result of processing (called "stdout" or standard output), and that is "data". The other is the error messages (called "stderr" or standard error), and that's "error". All of service output goes to "data", except from \fBreport-error\fP and \fBprint-format\fP (with "to-error" clause) which goes to "error". Note that "data" and "error" streams can be co-mingled when output by the service, but they will be obtained separately. This allows for clean separation of output from any error messages.

You can obtain service reply when it's ready in its entirety (likely most often used), or as it comes alone bit by bit (see more about asynchronous hooks further here).

.LP
.B STATUS OF REQUEST EXECUTION
.LP

"req_status" member of "gg_cli" type is the request status when a request had executed; it is somewhat similar to an exit status of a program. A Golf service request returns status by means of \fBexit-status\fP statement. Note that "req_status" is valid only if "gg_cli_request()" returned GG_OKAY (or if "return_code" is GG_OKAY for multi-threaded programs).

.LP
.B GETTING DATA REPLY (STDOUT)
.LP

Data returned from a request is valid only if "gg_cli_request()" returned GG_OKAY (or if "return_code" is GG_OKAY for multi-threaded programs). In that case, use "gg_cli_data()" function, for example:

.RS 4
.EX

// Declare and initialize request variable
gg_cli req = {0};
// Setup the req variable
\[char46]..
// Execute request
if (gg_cli_request (&req) == GG_OKAY) {
    char *data = gg_cli_data (req); // data response
    int data_len = req->data_len; // length of data response in bytes
}

.EE
.RE

"data_len" member of "gg_cli" type will have the length of data response in bytes. The reply is always null-terminated as a courtesy, and "data_len" does not include the terminating null byte.

"gg_cli_data()" returns the actual response (i.e. data output) from service as passed to "data" stream. Any output from service will go there, except when "to-error" clause is used in \fBprint-format\fP - use these constructs to output errors without stopping the service execution. Additionally, the output of \fBreport-error\fP will also not go to data output.

.LP
.B GETTING ERROR REPLY (STDERR)
.LP

An error reply returned from a service is valid only if "gg_cli_request()" returned GG_OKAY (or if "return_code" is GG_OKAY for multi-threaded programs). In that case, use "gg_cli_error()" function, for example:

.RS 4
.EX

// Declare and initialize request variable
gg_cli req = {0};
// Setup the req variable
\[char46]..
// Execute request
if (gg_cli_request (&req) == GG_OKAY) {
    char *err = gg_cli_error (req); // error response
    int err_len = req->error_len; // length of error response in bytes
}

.EE
.RE

"gg_cli_error()" returns any error messages from a service response, i.e. data passed to "error" stream. It is comprised of any service output when "to-error" clause is used in \fBprint-format\fP, as well as any output from \fBreport-error\fP. 

"error_len" member (of "gg_cli" type above) will have the length of error response in bytes. The response is always null-terminated as a courtesy, and "error_len" does not include the terminating null byte.

.LP
.B FREEING THE RESULT OF A REQUEST
.LP

Once you have obtained the result of a request, and when no longer needed, you should free it by using "gg_cli_delete()":

.RS 4
.EX

// Declare and initialize request variable
gg_cli req = {0};
// Setup the req variable
\[char46]..
// Execute request
gg_cli_request (&req);
// .. Use the result ..
// Free request output (data and error streams)
gg_cli_delete (&req);

.EE
.RE

If you do not free the result, your program may experience a memory leak. If your program exits right after issuing any request(s), you may skip freeing results as that is automatically done on exit by the Operating System. 

You can use "gg_cli_delete()" regardless of whether "gg_cli_request()" returned GG_OKAY or not.

.LP
.B COMPLETION HOOK
.LP

A function you wrote can be called when a request has completed. This is useful in multithreaded invocations, where you may want to receive complete request's results as they are available. To specify a completion hook, you must write a C function with the following signature and assign it to "done_hook" member of "gg_cli" typed variable:

.RS 4
.EX

typedef void (*gg_cli_done_hook)(char *recv, int recv_len, char *err, int err_len, gg_cli *req);

.EE
.RE

"recv" is the request's data output, "recv_len" is its length in bytes, "err" is the request's error output, and "err_len" is its length in bytes. "req" is the request itself which you can use to obtain any other information about the request. In a single threaded environment, these are available as members of the request variable of "gg_cli" type used in the request, and there is not much use for a completion hook. 

See an example with asynchronous hooks.

.LP
.B ASYNCHRONOUS HOOKS
.LP

You can obtain the service's reply as it arrives by specifying read hooks. This is useful if the service supplies partial replies over a period of time, and your application can get those partial replies as they become available.

To specify a hook for data output (i.e. from stdout), you must write a C function with the following signature and assign it to "out_hook":

.RS 4
.EX

typedef void (*gg_cli_out_hook)(char *recv, int recv_len, gg_cli *req);

.EE
.RE

"recv" is the data received and "recv_len" is its length.

To specify a hook for error output (i.e. from stderr), you must write a C function with the following signature and assign it to "err_hook":

.RS 4
.EX

typedef void (*gg_cli_err_hook)(char *err, int err_len, gg_cli *req);

.EE
.RE

"err" is the error received and "err_len" is its length.

"req" (in both hooks) is the request itself which you can use to obtain any other information about the request.

To register these functions with "gg_cli_request()" function, assign their pointers to "out_hook" and "err_hook" members of request variable of type "gg_cli" respectively. Note that the output hook (i.e. hook function of type "gg_cli_out_hook") will receive empty string ("") in "recv" and "recv_len" will be 0 when the request has completed, meaning all service output (including error) has been received. 

For example, functions "get_output()" and "get_err()" will capture data as it arrives and print it out, and get_complete() will print the final result:

.RS 4
.EX

// Output hook
void get_output(char *d, int l, gg_cli *req)
{
    printf("Got output of [%.*s] of length [%d] in thread [%d]", l, d, l, req->thread_id);
}

// Error hook
void get_err(char *d, int l, gg_cli *req)
{
    printf("Got error of [%.*s] of length [%d], status [%d]", l, d, l, req->req_status);
}

// Completion hook
void get_complete(char *data, int data_len, char *err, int err_len, gg_cli *req)
{
    printf("Got data [%.*s] of length [%d] and error of [%.*s] of length [%d], status [%d], thread [%d]\en", data_len, data, data_len, err_len, err, err_len, req->req_status, req->thread_id);
}

\[char46]..

gg_cli req = {0};
\[char46]..
// Register output and error hooks, as well as a completion hook
req.out_hook = &get_output;
req.err_hook = &get_err;
req.done_hook = &get_complete;


.EE
.RE


.LP
.B MULTITHREADING
.LP

The Golf client is MT-safe, meaning you can use it both in single-threaded and multi-threaded programs. Note that each thread must have its own copy of "gg_cli" request variable, since it provides both input and output parameters to a request call and as such cannot be shared between the threads.

.LP
.B USAGE
.LP

Do not use this API directly with Golf - use \fBcall-remote\fP instead which is made specifically for use in .golf files. Otherwise, you can use this API with any program.

.LP
.B USING API WITHOUT GOLF
.LP

You can use API without installing Golf. To do that:

.RS 4
\[bu]    
get the Golf source code,

.RE

.RS 4
\[bu]    
copy source files "gcli.c" and "gcli.h" to where you need to build your program,

.RE

.RS 4
\[bu]    
add the content of Golf's "LICENSE" file to your own in order to include the license for these source files,

.RE

.RS 4
\[bu]    
then make your application:

.RS 4
.EX

gcc -o cli cli.c gcli.c

.EE
.RE


.RE

Note that you do not need to install any other dependencies, as API is entirely contained in the aforementioned source files.

.SH EXAMPLES

.LP
.B SIMPLE EXAMPLE
.LP

The following example is a simple demonstration, with minimum of options used. Copy the C code to file "cli.c" in a directory of its own:

.RS 4
.EX

\[char35]include "gcli.h"

void main ()
{
    // Request type gg_cli - create a request variable and zero it out
    gg_cli req = {0};

    req.server = "/var/lib/gg/helloworld/sock/sock"; // Unix socket
    req.req_method = "GET"; // GET HTTP method
    req.app_path = "/helloworld"; // application path
    req.req = "/hello-simple"; // request name

    // Make a request
    int res = gg_cli_request (&req);

    // Check return status, and if there's an error, display error code and the
    // corresponding error message. Otherwise, print out service response.
    if (res != GG_OKAY) printf("Request failed [%d] [%s]\en", res, req.errm);
    else printf("%s", gg_cli_data(&req));

    // Free up resources so there are no memory leaks
    gg_cli_delete(&req);
}

.EE
.RE

To make this client application:

.RS 4
.EX

gcc -o cli cli.c $(gg -i)

.EE
.RE

In this case, you're using a Unix socket to communicate with the Golf service. To test with a Golf service handler, copy the following code to "hello_simple.golf" file in a separate directory:

.RS 4
.EX

begin-handler /hello_simple public
   silent-header
   @Hi there!
end-handler

.EE
.RE

Create and make the Golf application and run it via local Unix socket:

.RS 4
.EX

sudo mgrg -i -u $(whoami) helloworld
gg -q
mgrg -m quit helloworld
mgrg -w 1 helloworld

.EE
.RE

Run the client:

.RS 4
.EX

\[char46]/cli

.EE
.RE

The output is, as expected:

.RS 4
.EX

Hi there!

.EE
.RE


.LP
.B EXAMPLE WITH MORE OPTIONS
.LP

This example demonstrates using multiple options, including using TCP sockets connecting to a host and port number, environment variables, query string, request body and request execution timeout. It will also show the separation of "data" and "error" (i.e. stdout and stderr) streams from the service.

Copy this to file "cli1.c" in a directory of its own - note that in this example a server will run on localhost (127.0.0.1) and TCP port 2301:

.RS 4
.EX

\[char35]include "gcli.h"

void main ()
{
    // Request type gg_cli - create a request variable
    gg_cli req;
    // Initialize request
    memset (&req, 0, sizeof(req));

    // Add 3 environment variables (in the form of name, value, name, value, ... , NULL)
    char *env[] = { "REMOTE_USER", "John", "SOME_VAR", "SOME\enVALUE", "NEW_VAR", "1000", NULL };

    // Create a request
    // Environment variables to pass to service request
    req.env = env;
    // Server IP and port
    req.server = "127.0.0.1:2301";
    // Request method
    req.req_method = "GET";
    // Application path
    req.app_path = "/helloworld";
    // Request
    req.req = "/hello";
    // URL parameters (path and query string)
    req.url_params = "par1=val1&par2=91";
    // Content type
    req.content_type = "application/json";
    // Content (i.e. request body)
    req.req_body = "This is request body";
    // Content length
    req.content_len = strlen (req.req_body);
    // No timeout (set to 0)
    req.timeout = 0;

    // Make a request
    int res = gg_cli_request (&req);

    // Check return status, and if there's an error, display error code and the
    // corresponding error message
    if (res != GG_OKAY) printf("Request failed [%d] [%s]\en", res, req.errm);
    else {
       // If successful, display request results
       // Exit code from the service processing
       printf("Server status %d\en", req.req_status);
       // Length of reply from service
       printf("Len of data %d\en", req.data_len);
       // Length of any error from service
       printf("Len of error %d\en", req.error_len);
       // Reply from service
       printf("Data [%s]\en", gg_cli_data(&req));
       // Any error message from service
       printf("Error [%s]\en", gg_cli_error(&req));
    }

    // Free up resources so there are no memory leaks
    gg_cli_delete(&req);
}

.EE
.RE

Note that the URL parameters (i.e. "req.url_params") could have been written as a combination of a path segment and query string (see \fBrequest\fP):

.RS 4
.EX

req.url_params = "/par1/val1?par2=91";

.EE
.RE

or just as a path segment:

.RS 4
.EX

req.url_params = "/par1=val1/par2=91";

.EE
.RE

To make this client application:

.RS 4
.EX

gcc -o cli1 cli1.c $(gg -i)

.EE
.RE

To test it, you can create a Golf application. Copy this to "hello.golf" file in a separate directory:

.RS 4
.EX

begin-handler /hello public
    silent-header

    // Get request body
    request-body rb

    // Input params
    get-param par1
    get-param par2

    // Get environment variables passed on from the client
    get-sys environment "REMOTE_USER" to ruser
    get-sys environment "SOME_VAR" to somev
    get-sys environment "NEW_VAR" to newv

    // Output, print the environment variables, the PID of server process and the request body received from the client
    get-req process-id to pid
    @Hello World! [<<print-out ruser>>] [<<print-out somev>>] [<<print-out newv>>] [<<print-out par1>>] [<<print-out par2>>] <<print-out pid>> <<print-out rb>>

    // Output back a number of lines, generally as "Output line #<num of line>"
    // After line #1418, print out "Line 1419 has an error" to stderr
    // After line #4418, report an error and exit
    // This demonstrates outputting data to both stdout and stderr
    start-loop repeat 8000 use i start-with 0
        @Output line #<<print-out i>>
        if-true i equal 1419
            print-format "Line %ld has an error\en", i to-error
        end-if
        if-true i equal 4419
            // Exit code of the service execution
            exit-status 82
            report-error "%s", "Some error!"
        end-if
    end-loop
end-handler

.EE
.RE

Create and make the Golf application and run it on local TCP port 2301 to match the client above:

.RS 4
.EX

sudo mgrg -i -u $(whoami) helloworld
gg -q
mgrg -m quit helloworld
mgrg -w 1 -p 2301 helloworld

.EE
.RE

Run the client:

.RS 4
.EX

\[char46]/cli1

.EE
.RE

The output:

.RS 4
.EX

Server status 82
Len of data 78530
Len of error 35
Data [Hello World! [John] [SOME
VALUE] [1000] [val1] [91] 263002 This is request body
Output line #0
Output line #1
Output line #2
Output line #3
Output line #4
Output line #5
Output line #6
Output line #7

\[char46]..
Output line #4413
Output line #4414
Output line #4415
Output line #4416
Output line #4417
Output line #4418
Output line #4419
]
Error [Line 1419 has an error
Some error!
]

.EE
.RE

The output shows service exit code (82, see \fBexit-status\fP in the Golf code above), length of data output, and other information which includes environment variables passed to the service from the client, the PID of server process, the request body from the client, and then the error output. Note that the data output (stdout) and the error output (stderr) are separated, since the protocol does use separate streams over the same connection. This makes working with the output easy, while the data transfer is fast at the same time.
.SH SEE ALSO
 API

\fBClient-API\fP  
\fBServer-API\fP   
See all 
\fBdocumentation\fP