Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace REST with JSON-RPC #1644

Merged
merged 189 commits into from
Oct 20, 2023
Merged

Replace REST with JSON-RPC #1644

merged 189 commits into from
Oct 20, 2023

Conversation

emmiegit
Copy link
Member

@emmiegit emmiegit commented Oct 9, 2023

Since we've finalized use of DEEPWELL as an internal API only, external-facing requirements no longer apply. We've already removed things like per-IP ratelimiting and now we've been facing a limitation of REST APIs, which is our desire to send more rich error data than one of a handful of relevant HTTP status codes. As such, we're shifting to a JSON-RPC-based internal API for DEEPWELL, which gets rid of the unnecessary HTTP complexities we don't need, and instead essentially has a remote method invocation system, with serde_json-backed serialization for input/output. tide (the web server) has been entirely removed, and so a lot of the lines changed are from log line diffs.

Likewise, I have taken the existing services::Error object and made it have a larger number of more specific error cases, since we are now sending those over the wire instead of bunching them into much more vague HTTP statuses.

I have also been able to use the transaction closure, which is wrapped outside of each method. Thus, boilerplate related to setting up the transaction and ensuring it is committed is now removed. For most methods, this means the wrapper code is very simple. Take the message_draft_send method:

pub async fn message_draft_send(
    ctx: &ServiceContext<'_>,
    params: Params<'static>,
) -> Result<MessageRecordModel> {
    let SendMessageDraft { message_draft_id } = params.parse()?;
    info!("Sending message draft with ID {message_draft_id}");
    MessageService::send(ctx, &message_draft_id).await
}

For local testing of DEEPWELL (for instance, using curl), the endpoint is now POST http://localhost:2747/jsonrpc. This always returns HTTP 200, error information is passed in the JSON result, in accordance with the JSON-RPC standard. I have modified the necessary code in framerail as well, and refactored it a bit. There, we are now using the json-rpc-2.0 library to act as a JSON-RPC client.

@emmiegit emmiegit self-assigned this Oct 9, 2023
@emmiegit emmiegit force-pushed the WJ-1192-rpc branch 2 times, most recently from ceb7201 to 5339cff Compare October 16, 2023 05:00
@emmiegit emmiegit changed the title Replace REST with JSONRPC Replace REST with JSON-RPC Oct 16, 2023
@codecov
Copy link

codecov bot commented Oct 20, 2023

Codecov Report

Merging #1644 (3f34e9c) into develop (6ccb1ce) will decrease coverage by 39.28%.
The diff coverage is 2.19%.

Impacted file tree graph

@@             Coverage Diff             @@
##           develop   #1644       +/-   ##
===========================================
- Coverage    41.02%   1.75%   -39.28%     
===========================================
  Files          342     129      -213     
  Lines        10537    5128     -5409     
===========================================
- Hits          4323      90     -4233     
+ Misses        6214    5038     -1176     
Flag Coverage Δ
deepwell 1.75% <2.19%> (+0.02%) ⬆️
ftml ?
Files Coverage Δ
deepwell/src/config/file.rs 10.76% <ø> (ø)
deepwell/src/models/alias.rs 0.00% <ø> (ø)
deepwell/src/models/file.rs 0.00% <ø> (ø)
deepwell/src/models/file_revision.rs 0.00% <ø> (ø)
deepwell/src/models/filter.rs 0.00% <ø> (ø)
deepwell/src/models/message.rs 0.00% <ø> (ø)
deepwell/src/models/message_recipient.rs 0.00% <ø> (ø)
deepwell/src/models/message_record.rs 0.00% <ø> (ø)
deepwell/src/models/message_report.rs 0.00% <ø> (ø)
deepwell/src/models/page.rs 0.00% <ø> (ø)
... and 88 more

... and 209 files with indirect coverage changes

@emmiegit
Copy link
Member Author

thanks @Yossipossi1

@emmiegit emmiegit merged commit 5418bc3 into develop Oct 20, 2023
13 checks passed
@emmiegit emmiegit deleted the WJ-1192-rpc branch October 20, 2023 02:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants