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

Pi/endpoint macro #4

Merged
merged 5 commits into from
Sep 23, 2021

Conversation

Quantumplation
Copy link
Contributor

A macro_rules macro to make defining endpoints easier;

The syntax is:

endpoints! {
  /// Description
  function_name(param: type) -> Return => "route";
    ("link_to_docs"),
  ...
}

In theory supports multiple parameters, different types, etc.

Macros can be a bit dense, so I tried to document how it works; If it causes an issue in the future, tag me and I'll be happy to help fix it!

@Quantumplation
Copy link
Contributor Author

Resolves #3

@marcospb19 marcospb19 linked an issue Sep 23, 2021 that may be closed by this pull request
@marcospb19
Copy link
Collaborator

Amazing, I loved the macro docs, merged!

@marcospb19 marcospb19 merged commit 8ed95ba into blockfrost:master Sep 23, 2021
@Quantumplation Quantumplation deleted the pi/endpoint-macro branch September 23, 2021 17:38
@marcospb19
Copy link
Collaborator

If proc-macros were to be easier to implement, we could use them to generate the doc URL in compile time.

Instead of:

impl BlockFrostApi {
    endpoints! {
        /// Return the content of a requested block for a specific slot in an epoch.
        blocks_by_epoch_and_slot(epoch_number: Integer, slot_number: Integer) -> Block => "/blocks/epoch/{epoch_number}/slot/{slot_number}";
        ("https://docs.blockfrost.io/#tag/Cardano-Blocks/paths/~1blocks~1epoch~1{epoch_number}~1slot~1{slot_number}/get"),

        /// Return the list of blocks following a specific block.
        blocks_next(hash_or_number: String) -> Vec<Block>  "/blocks/{hash_or_number}/next";
            ("https://docs.blockfrost.io/#tag/Cardano-Blocks/paths/~1blocks~1{hash_or_number}~1next/get"),
    }
}

Use this:

#[endpoints]
impl BlockFrostApi {
    /// Return the content of a requested block for a specific slot in an epoch.
    blocks_by_epoch_and_slot(epoch_number: Integer, slot_number: Integer) -> Block { "/blocks/epoch/{epoch_number}/slot/{slot_number}" }

    /// Return the list of blocks following a specific block.
    blocks_next(hash_or_number: String) -> Vec<Block> { "/blocks/{hash_or_number}/next" }
}

It would just need to replace "/" by "~1".

Maybe in the future, who knows.

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.

Condensed endpoint declaration macro
2 participants