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

Improve system api to perform HTTP requests #2631

Draft
wants to merge 22 commits into
base: main
Choose a base branch
from

Conversation

jvff
Copy link
Contributor

@jvff jvff commented Oct 15, 2024

Motivation

Linera applications can perform HTTP requests to external services, but the available http_post API was very limited, and prevented applications from configuring the request. This is often needed in order to add custom headers, for example for authentication.

Proposal

Replace the http_post API with a broader http_request API, which allows sending more configurable http::Requests, and returns a more detailed http::Response.

Test Plan

TODO

Release Plan

  • Backporting is not possible but we may want to deploy a new devnet and release a new
    SDK soon.
  • Contains breaking changes to the WIT interface and to the linera-sdk API.

Links

@jvff jvff added the enhancement New feature or request label Oct 15, 2024
@jvff jvff added this to the Testnet #2 milestone Oct 15, 2024
@jvff jvff self-assigned this Oct 15, 2024
@jvff jvff force-pushed the improve-http-request-system-api branch 3 times, most recently from 0f528cb to 2cc7ab5 Compare October 21, 2024 14:34
@jvff jvff force-pushed the improve-http-request-system-api branch from 2cc7ab5 to 550315e Compare December 18, 2024 19:12
jvff added 22 commits January 14, 2025 20:14
Make it easier to find feature definitions.
Prepare to allow applications to specify the HTTP method to use.
Prepare to support other HTTP methods.
Allow specifying which HTTP method should be used for the request.
Allow specifying multiple headers for the request.
Use a broader name since now the HTTP method can be specified.
They don't seem to be used.
Make it simpler to tweak how it is serialized and formatted for debug
output.
Represent useful information from an HTTP response.
Instead of just the response body.
Collect all the parameters for `http_request` into a single type.
Simplify the API a bit, and make it simpler to change the types in the
future if needed.
Allow creating some simple common HTTP requests.
Make it easy to add headers to `http::Request`s.
The API is already available in the WIT interface, so it makes sense to
expose it in a more discoverable way.
Allow services to write unit tests using the new API.
Provide access to the `http::Request` and `http::Response` types needed
to use the APIs.
Allow it to be enabled for testing.
Make it simple to create a new `Response` with just a status code and no
headers or body.
Make it easy to build simple success responses.
Make it easy to build simple unauthorized error responses.
Make it easy to add headers to `http::Response`s.
@jvff jvff force-pushed the improve-http-request-system-api branch from 550315e to 26a5299 Compare January 15, 2025 02:06
/// A POST request.
Post,

/// A PUT request.
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we support all these methods?

@Twey
Copy link
Contributor

Twey commented Jan 20, 2025

This is often needed in order to add custom headers, for example for authentication.

Where do we expect the contract (whose state and code are both public) to get this information? 🤔

@jvff
Copy link
Contributor Author

jvff commented Jan 20, 2025

This is often needed in order to add custom headers, for example for authentication.

Where do we expect the contract (whose state and code are both public) to get this information? 🤔

This use case specifically was needed in the service for the airdrop demo. But yeah, for contracts other custom headers might be more relevant.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
Status: No status
Development

Successfully merging this pull request may close these issues.

3 participants