protocol | bank-client | bank-server-socket | bank-server-graphql | bank-server-rabbitmq
Java socket implementation for the server backend. The client counterpart can be found here.
A simple text protocol ensures consent between server/client (see chapter Protocol.)
Historically this was the first backend implementation, which is why most other implementations rely on the text protocol specified here. That is because the protocol models the banking domain pretty well (i.e. banking operations, results, errors etc. see Actions, Status Codes) which makes it convenient to use on top of other technologies/protocols such as http, websocket, message queues etc.
In your IDE, run bank.Server
as Java Application.
Or execute the script ./run_server.sh
(make sure to grant execution rights chmod u+x run_server.sh
)
Or with gradle gradle run
Or use the docker image docker run --rm -p 5001:5001 mikenoethiger/bank-server-socket
Use any TCP/IP client to connect to the server and send a request according to the Protocol (e.g. with nc nc localhost 5001
)
Or use the Client
CLI program: ./run_client.sh
(make sure to grant execution rights chmod u+x run_client.sh
)
E.g. to create an account:
$ ./run_client.sh localhost 5001 3 mike
If you want to connect from java code, take a look here.
Communication between server and client is established through sockets. A simple text protocol ensures consent between the parties. This chapter explains in detail how this protocol works. You might want to jump to the Actions chapter if you're only interested in the usages / API specification.
Request refers to data that is sent from client to server. Response refers to data that is sent from server to client.
Each request shall adhere to the following format:
action
[argument1]
[argument2]
action
: An integer value, stating the requested action to take placeargument_n
: Variadic argument list, that is zero or more arguments wich augment the action. Details on arguments can be found in the Actions chapter.- The delimiter between described request parts is the new line character
\n
- The request ends with two consecutive new line characters
\n\n
Actual request encoding:
action\n[argument1]\n[argument2]\n\n
Each response shall adhere to the following format:
[status_code]
[response_data1]
[response_data2]
status_code
: An integer representing the status of the processed request (0=ok, everything else is an error code.) See Status Codes for details on status codes.response_data_n
: Zero or more lines containing response data for the requested action. If status code is an error, the first line of response data is the error description by convention. See Actions chapter for response data documentation.- Response data is delimited with the new line character
\n
- The whole response ends with two consecutive new line characters
\n\n
Actual response encoding:
[status_code]\n[response_data1]\n[response_data2]\n\n
This chapter is a summary of available actions. An action is something that a client can request the server to perform using the custom text protocol.
Terminology
account
: (string) Account numberowner
: (string) The name of an account ownerbalance
: (float) An account balanceactive
: (int) Denotes whether an account is active/inactive.0
denotes an inactive account, every other integer denotes an active account
Sometimes, multiple entities of the same type appear in one request/response, in these cases above terms are suffixed with anything meaningful, but yet still adhere to above description, e.g. account_from
and account_to
are both of type account
.
Variadic entities are suffixed with _0
and _n
, e.g.
account_0
account_n
Means zero or more accounts may follow.
For the sake of compactness, the terminating \n\n
is omitted in all stated requests/responses.
Request:
1
Success Response:
0
account_1
account_n
Request:
2
account
Success Response:
0
account
owner
balance
active
Errors: 1 Account does not exist
Request:
3
owner
Success Response:
0
account
owner
balance
active
Errors: 2 Account could not be created
Request:
4
account
Success Response:
0
Errors: 1 Account does not exist | 3 Account could not be closed
Request:
5
account_from
account_to
amount
Success Response:
0
balance_from
balance_to
Errors: 1 Account does not exist | 4 Inactive account | 5 Account overdraw | 6 Illegal argument
Request:
6
account
amount
Success Response:
0
balance
Errors: 1 Account does not exist | 4 Inactive account | 6 Illegal argument
Request:
7
account
amount
Sucess Response:
0
balance
Errors: 1 Account does not exist | 4 Inactive account | 5 Account overdraw | 6 Illegal argument
Status Code | Description |
---|---|
0 | OK |
1 | Account does not exist. |
2 | Account could not be created. |
3 | Account could not be closed. |
4 | Inactive account. |
5 | Account overdraw. |
6 | Illegal argument. |
7 | Bad request. |
8 | Internal Error. |
Copyright 2020 Mike Nöthiger (noethiger.mike@gmail.com)
This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 3 of the License.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with this program (COPYING file.) If not, see https://www.gnu.org/licenses/.