Skip to content

Conversation

@gregorydemay
Copy link
Collaborator

@gregorydemay gregorydemay commented Jul 11, 2025

Example of a canister using the canhttp library to make a simple HTTP post request.

@gregorydemay gregorydemay changed the base branch from main to XC-427-improve-cycles-layer July 31, 2025 13:12
@gregorydemay gregorydemay marked this pull request as ready for review July 31, 2025 14:35
@gregorydemay gregorydemay requested a review from a team as a code owner July 31, 2025 14:35
@gregorydemay gregorydemay requested a review from lpahlavi July 31, 2025 14:36
gregorydemay added a commit that referenced this pull request Aug 11, 2025
Refactor the trait `CyclesChargingPolicy` to make it easier to configure
cycles accounting when building a service as shown in the examples of #6
.

**BREAKING CHANGE**: The trait `CyclesChargingPolicy` was changed as
follows:

1. The method `cycles_to_charge` that only computed the amount of cycles
to charge was removed.
2. A new method `charge_cycles` that does the actual charging was
introduced as well as several implementations such as `ChargeMyself` or
`ChargeCaller` that can be used to achieve the same functionalty as
before.
Base automatically changed from XC-427-improve-cycles-layer to main August 11, 2025 12:31
# Conflicts:
#	canhttp/src/cycles/mod.rs
Copy link
Contributor

@lpahlavi lpahlavi left a comment

Choose a reason for hiding this comment

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

Thanks a lot for the PR @gregorydemay! LGTM, just 1-2 mini-nits from me.

@gregorydemay gregorydemay merged commit cedce59 into main Aug 25, 2025
13 of 14 checks passed
@gregorydemay gregorydemay deleted the gdemay/XC-427-examples branch August 25, 2025 07:05
@github-actions github-actions bot mentioned this pull request Oct 8, 2025
lpahlavi added a commit that referenced this pull request Oct 20, 2025
## 🤖 New release

* `canhttp`: 0.2.1 -> 0.3.0 (⚠ API breaking changes)

### ⚠ `canhttp` breaking changes

```text
--- failure enum_missing: pub enum removed or renamed ---

Description:
A publicly-visible enum cannot be imported by its prior path. A `pub use` may have been removed, or the enum itself may have been renamed or removed entirely.
        ref: https://doc.rust-lang.org/cargo/reference/semver.html#item-remove
       impl: https://github.com/obi1kenobi/cargo-semver-checks/tree/v0.41.0/src/lints/enum_missing.ron

Failed in:
  enum canhttp::CyclesAccountingError, previously in file /tmp/.tmpHTwER4/canhttp/src/cycles/mod.rs:100

--- failure struct_missing: pub struct removed or renamed ---

Description:
A publicly-visible struct cannot be imported by its prior path. A `pub use` may have been removed, or the struct itself may have been renamed or removed entirely.
        ref: https://doc.rust-lang.org/cargo/reference/semver.html#item-remove
       impl: https://github.com/obi1kenobi/cargo-semver-checks/tree/v0.41.0/src/lints/struct_missing.ron

Failed in:
  struct canhttp::IcHttpRequestWithCycles, previously in file /tmp/.tmpHTwER4/canhttp/src/client/mod.rs:100
  struct canhttp::CyclesCostEstimator, previously in file /tmp/.tmpHTwER4/canhttp/src/cycles/mod.rs:28
  struct canhttp::CyclesAccounting, previously in file /tmp/.tmpHTwER4/canhttp/src/cycles/mod.rs:114

--- failure struct_with_pub_fields_changed_type: struct with pub fields became an enum or union ---

Description:
A struct with pub fields became an enum or union, breaking accesses to its public fields.
        ref: obi1kenobi/cargo-semver-checks#297 (comment)
       impl: https://github.com/obi1kenobi/cargo-semver-checks/tree/v0.41.0/src/lints/struct_with_pub_fields_changed_type.ron

Failed in:
  struct canhttp::IcError became enum in file /tmp/.tmpeFTXb6/canhttp/canhttp/src/client/mod.rs:46

--- failure trait_missing: pub trait removed or renamed ---

Description:
A publicly-visible trait cannot be imported by its prior path. A `pub use` may have been removed, or the trait itself may have been renamed or removed entirely.
        ref: https://doc.rust-lang.org/cargo/reference/semver.html#item-remove
       impl: https://github.com/obi1kenobi/cargo-semver-checks/tree/v0.41.0/src/lints/trait_missing.ron

Failed in:
  trait canhttp::CyclesChargingPolicy, previously in file /tmp/.tmpHTwER4/canhttp/src/cycles/mod.rs:10
```

<details><summary><i><b>Changelog</b></i></summary><p>

<blockquote>

## [0.3.0] - 2025-10-08

### Added
- **Breaking:** A new method `charge_cycles` that does the actual
charging was added to `CyclesChargingPolicy`
([#7](#7))
- Example of canister using the library to make HTTP requests
([#6](#6))

### Changed
- **Breaking:** Update `ic-cdk` to `v0.18.7` including several changes
to align with the new HTTP outcall API
([#21](#21)). Notably:
  - `IcError` is refactored into an enum
- Use of the new `HttpRequestArgs` and `HttpRequestResult` types in
`CyclesChargingPolicy` and `Client` trait impls
- Removal of `IcHttpRequestWithCycles`, `CyclesCostEstimator`,
`CyclesAccountingError` and `CyclesAccounting` due to the `ic-cdk`
method for making HTTP outcalls now taking care of charging cycles

[0.3.0]:
https://github.com/dfinity/canhttp/compare/canhttp-v0.2.1..canhttp-v0.3.0
</blockquote>


</p></details>

---
This PR was generated with
[release-plz](https://github.com/release-plz/release-plz/).

---------

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: Louis Pahlavi <louis.pahlavi@dfinity.org>
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