Skip to content
This repository has been archived by the owner on Aug 1, 2022. It is now read-only.

feat(proxy): demo warp based REST API endpoints #250

Closed
wants to merge 81 commits into from

Conversation

xla
Copy link
Contributor

@xla xla commented Mar 25, 2020

Alternative follow-up to #220, in response to the issues I see with pulling in Rocket as a dependency, which is at the core of the great prior work of @garbados in #226. Also just for brevity so we can compare our options as this approach uses our existing web stack based on warp.

To show an end-to-end integration I focused on the endpoint around projects as it forced me to handle CoCo and Registry equally as well as read and write operations. This includes serialisation of request inputs and response bodies, while trying to adhere to our strict separation of core domain and materialisation in one of our API. This approach is comparable to what we tried to achieve with our GraphQL API and the isolation of it in the graphql module.

  • Boostrap warp based REST stack
  • Introduce custom error infrastructure to translate core errors into JSON responses
  • Pass state down to filters and handlers
  • Implement project filters (create, get, list, register)
  • Implement project handlers (create, get, list, register)
  • Test end-to-end request chain

proxy/src/http/error.rs Outdated Show resolved Hide resolved
proxy/src/http/project.rs Outdated Show resolved Hide resolved
proxy/src/http/project.rs Outdated Show resolved Hide resolved
proxy/src/http/project.rs Outdated Show resolved Hide resolved
}
}

impl Serialize for project::Project {
Copy link

@jxs jxs Mar 25, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should Serialize impl'ed on crate::project instead of here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm on the fence, on one side it's nice to use the derive macros. On the other hand there will be slight diversion between the core types and how they are represented over something like a JSON API. And that is really a concern of the API layer for us http. Happy to hear arguments in the other direction.

proxy/src/http/project.rs Outdated Show resolved Hide resolved
proxy/src/http/project.rs Outdated Show resolved Hide resolved
proxy/src/http/project.rs Outdated Show resolved Hide resolved
proxy/src/http/project.rs Outdated Show resolved Hide resolved
proxy/src/project.rs Outdated Show resolved Hide resolved
@garbados
Copy link
Contributor

This looks like a good demo of how to do a REST API in Warp. Thanks @xla , this addresses the issues I ran into trying to do it myself. I've read through the implementation here and I'm prepared to move forward with it for the REST API over the Rocket implementation, echoing your concerns about dependency footprints.

Copy link
Member

@rudolfs rudolfs left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Impressive change-set!! 🌟 🥇 🍰

From my perspective the proxy part could be merged if it can run in parallel to the existing graphql endpoints until we have a good migration strategy for the front-end.

The front-end still feels like it needs quite a lot of work to make the features that got migrated to the REST back-end work as they did before.

If we want to move forward, I'd recommend splitting it up into to PRs and merging the back-end and continue working on the front-end.

mkdir -p "$CACHE_FOLDER/npm"
mkdir -p "$CACHE_FOLDER/yarn"
mkdir -p "$CACHE_FOLDER/cargo"
mkdir -p "$CACHE_FOLDER/rustup"


export CYPRESS_CACHE_FOLDER="$CACHE_FOLDER/cypress"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this and L24 didn't make any difference to the CI build stability and can be removed again.

package.json Outdated
"wait-on": "^4.0.1"
},
"scripts": {
"start": "run-p --race svelte:watch proxy:start graphiql:serve electron:start",
"start": "run-p --race svelte:watch proxy:start:test graphiql:serve electron:start",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I assume this will be reverted before merge?

package.json Outdated
@@ -87,7 +91,7 @@
"svelte:watch": "yarn svelte:clean && rollup -c -w",
"proxy:build": "cd proxy && cargo build --all-features --all-targets",
"proxy:build:release": "cd proxy && cargo build --release --all-features --all-targets",
"proxy:start": "cd proxy && cargo run --release -- --registry=emulator",
"proxy:start": "cd proxy && cargo run -- --registry=emulator",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ditto.

package.json Outdated
@@ -101,7 +105,7 @@
"prettier": "prettier \"**/*.@(js|json|svelte|css|html)\" --ignore-path .gitignore",
"prettier:check": "yarn prettier --check",
"prettier:write": "yarn prettier --write",
"lint": "eslint . --ignore-path .gitignore --ext .js,.svelte"
"lint": "eslint . --ignore-path .gitignore --ext js,.svelte,.ts"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is "js" vs ".js" a typo here?

proxy/API.md Outdated

The examples provided use [curl](https://curl.haxx.se/) and the [window.fetch](https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API/Using_Fetch) function available in the JavaScript environments of modern browsers.

### GET /projects
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should probably add a yarn script to start up the swagger live doc server and explain here how to use it and remove all the examples from this file.

proxy/Cargo.toml Outdated
@@ -30,7 +30,7 @@ tempfile = "3.1"
tokio = { version = "0.2", features = [ "macros" ] }
url17 = { package = "url", version = "1.7" }
url = "2.1"
warp = "0.2"
warp = { git = "https://github.com/radicle-dev/warp", branch = "openapi", features = [ "openapi" ] }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need a fork for this? Will the openapi stuff get merged into mainline, so we don't have to maintain our own fork?

"message".into(),
document::string()
.description("Human readable description of the error case")
.example("Malformed ID, supported charactes: [a-zA-Z0-9]"),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
.example("Malformed ID, supported charactes: [a-zA-Z0-9]"),
.example("Malformed ID, supported characters: [a-zA-Z0-9]"),

ui/App.svelte Outdated
@@ -62,6 +63,7 @@
}
`;

// TODO(sos): dev mode in which you don't have to sign in on reload
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This won't be necessary once identities are integrated at a protocol level in the backend. You'll create the identity once and it will persist across reboots.


state.end()
}
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would the avatar related code be moved out of the file when implementing the rest of the queries (avatar query and later adding avatars to orgs), or would this part of the code be repeated?

b: number;
};
emoji: string;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we use the types from avatar.ts here to avoid duplication?

@xla
Copy link
Contributor Author

xla commented Apr 20, 2020

Superseeded by #296

@xla xla closed this Apr 20, 2020
xla added a commit that referenced this pull request Apr 27, 2020
Follow-up to #250

* Implement project registration REST call
* Implement register REST call
* Remove outdated network query
* Replace gql user endpoints with REST
* Migrate to user REST endpoints
* Migrate to control REST endpoints
* Please le clippy
* Remove outdated graphql docs
* Fix typo
* Remove last traces
* Update proxy/src/lib.rs
Co-Authored-By: Rūdolfs Ošiņš <[email protected]>
@rudolfs rudolfs deleted the xla/220-warp-implementation branch May 12, 2020 16:13
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants