Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
cogsys
Dare2Del
Demonstrator - Reasoning WebAPI
Commits
c33b46d3
Commit
c33b46d3
authored
Nov 16, 2020
by
Sebastian Seufert
Browse files
- refined response handling as suggested by MS -> now json dict
parent
72a8449e
Changes
2
Hide whitespace changes
Inline
Side-by-side
include/common/api_response.pl
View file @
c33b46d3
...
...
@@ -12,6 +12,10 @@ This include provides simple formatting predicates that form a json response.
501 -> not implemented
*/
action_reply_success_dict
(
Code
,
Dict
)
:-
reply_json_dict
(
Dict
,
[
status
(
Code
)]).
/** Remove later
action_reply_success(Code, Msg) :-
format(atom(Reply), 'Endpoint: ~q', [Msg]),
reply_json(Reply, [status(Code)]).
...
...
@@ -19,18 +23,7 @@ action_reply_success(Code, Msg) :-
action_reply_success(Code, Endpoint, Action) :-
Reply =_{endpoint:Endpoint,action:Action},
reply_json(Reply, [status(Code)]).
action_reply_success
(
Code
,
Msg
,
Reply
)
:-
format
(
atom
(
Reply
),
'Endpoint: ~q'
,
[
Msg
]),
reply_json
(
Reply
,
[
status
(
Code
)]).
action_reply_success
(
Code
,
Endpoint
,
Action
,
Reply
)
:-
Reply
=
_
{
endpoint
:
Endpoint
,
action
:
Action
},
reply_json
(
Reply
,
[
status
(
Code
)]).
action_reply_success
(
Code
,
Endpoint
,
Action
,
Details
,
Reply
)
:-
Reply
=
_
{
endpoint
:
Endpoint
,
action
:
Action
,
details
:
Details
},
reply_json
(
Reply
,
[
status
(
Code
)]).
*/
generic_reply
(
Method
,
Pred
,
Info
)
:-
format
(
'Status: 201~n'
),
...
...
web_api.pl
View file @
c33b46d3
...
...
@@ -142,16 +142,13 @@ set_bg(Request) :-
sum_list
(
Accs
,
Total
)
;
assert_dict
(
Dict
,
Total
)
),
(
Diff
is
(
L
-
Total
),
(
% Total is 0 when no facts were added since already present
Total
is
0
->
action_reply_success
(
204
,
set_bg
,
'fact(s) already present, no change'
)
;
L
==
Total
->
format
(
atom
(
Message
),
'Received: ~q, Added: ~q'
,
[
L
,
Total
]),
action_reply_success
(
201
,
set_bg
,
Message
)
;
Diff
is
(
L
-
Total
),
format
(
atom
(
Message
),
'Received: ~q, Added: ~q, Skipped: ~q (already present)'
,
[
L
,
Total
,
Diff
]),
action_reply_success
(
201
,
set_bg
,
Message
)
->
action_reply_success_dict
(
204
,
_
{
received
:
L
,
added
:
Total
,
skipped
:
Diff
})
;
action_reply_success_dict
(
201
,
_
{
received
:
L
,
added
:
Total
,
skipped
:
Diff
})
).
/**
...
...
@@ -200,12 +197,10 @@ clear_bg(Req) :-
),
(
Failed
==
[]
->
format
(
atom
(
Message
),
'Received: ~q, Removed: ~q'
,
[
Length
,
Length
]),
action_reply_success
(
200
,
clear_bg
,
Message
)
->
action_reply_success_dict
(
200
,
_
{
received
:
Length
,
removed
:
Length
})
;
length
(
Failed
,
FailedCnt
),
Diff
is
(
Length
-
FailedCnt
),
format
(
atom
(
Message
),
'Received: ~q, Removed: ~q, Skipped: ~q (not found)'
,
[
Length
,
Diff
,
FailedCnt
]),
action_reply_success
(
200
,
clear_bg
,
Message
)
action_reply_success_dict
(
200
,
_
{
received
:
Length
,
removed
:
Diff
,
skipped
:
FailedCnt
})
).
/**
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment