README

marianoguerra/megalodon/api does not have a README file

#
Transport

pub(open) trait Transport {
async fn send(Self, HttpRequest) -> HttpResponse
fn describe(Self) -> String
}

The portable seam between request construction and an HTTP implementation. Implementations should translate runtime/network failures to RequestFailed; status-code interpretation stays in the portable core.

#
MegalodonError

pub(all) suberror MegalodonError {
InvalidRequest(String)
RequestFailed(String)
HttpStatus(status~ : Int, body~ : String, headers~ : Map[String, String])
PartialContent(headers~ : Map[String, String])
InvalidJson(String)
InvalidEntity(entity~ : String, detail~ : String)
UnknownServer(String)
NodeInfo(String)
} derive(
Debug
)

#
MegalodonError::describe_error

fn MegalodonError::describe_error(self : MegalodonError) -> String

#
MegalodonError::status

fn MegalodonError::status(self : MegalodonError) -> Int?

#
HttpMethod

pub(all) enum HttpMethod {
Get
Post
Put
Patch
Delete
} derive(Eq,
Debug
)

An HTTP method supported by the Mastodon-compatible REST API.

#
HttpMethod::to_string

fn HttpMethod::to_string(self : HttpMethod) -> String

#
HttpRequest

pub(all) struct HttpRequest {
url : String
http_method : HttpMethod
headers : Map[String, String]
body : Bytes
} derive(Eq,
Debug
)

A fully encoded outbound request. Transports must not reinterpret body.

#
HttpRequest::body_text

fn HttpRequest::body_text(self : HttpRequest) -> String

#
HttpRequest::content_length

fn HttpRequest::content_length(self : HttpRequest) -> Int

#
HttpResponse

pub(all) struct HttpResponse {
status : Int
headers : Map[String, String]
body : Bytes
} derive(Eq,
Debug
)

#
HttpResponse::body_text

fn HttpResponse::body_text(self : HttpResponse) -> String

#
HttpResponse::header

fn HttpResponse::header(self : HttpResponse, name : String) -> String?

#
MultipartBody

pub(all) struct MultipartBody {
content_type : String
body : Bytes
} derive(Eq,
Debug
)

pub(all) struct Pagination {
next : String?
prev : String?
} derive(Eq,
Debug
)

#
ParamValue

pub(all) enum ParamValue {
Str(String)
Int(Int64)
Bool(Bool)
Strs(Array[String])
Ints(Array[Int64])
} derive(Eq,
Debug
)

#
Params

pub(all) struct Params {
entries : Array[(String, ParamValue)]
} derive(Eq,
Debug
)

Ordered parameters permit repeated keys and deterministic tests.

#
Params::encode

fn Params::encode(self : Params) -> String

#
Params::new

fn Params::new() -> Params

#
Params::of

fn Params::of(entries : Array[(String, ParamValue)]) -> Params

#
Params::put

fn Params::put(self : Params, key : String, value : ParamValue) -> Unit

#
Params::put_bool

fn Params::put_bool(self : Params, key : String, value : Bool?) -> Unit

#
Params::put_int

fn Params::put_int(self : Params, key : String, value : Int64?) -> Unit

#
Params::put_opt

fn Params::put_opt(self : Params, key : String, value : ParamValue?) -> Unit

#
Params::put_string

fn Params::put_string(self : Params, key : String, value : String?) -> Unit

#
Params::put_strings

fn Params::put_strings(self : Params, key : String, value : Array[String]?) -> Unit

#
RequestBody

pub(all) enum RequestBody {
Empty
Json(Json)
Form(Params)
Raw(bytes~ : Bytes, content_type~ : String)
} derive(Eq,
Debug
)

#
Response

pub(all) struct Response[T] {
data : T
status : Int
headers : Map[String, String]
pagination : Pagination
} derive(Eq,
Debug
)

#
Response::map

fn[A, B] Response::map(self : Response[A], f : (A) -> B) -> Response[B]

#
USER_AGENT

let USER_AGENT : String

#
build_request

fn build_request(base_url : String, path : String, http_method : HttpMethod, query? : Params, body? : RequestBody, access_token? : String, user_agent? : String, extra_headers? : Map[String, String]) -> HttpRequest

#
interpret

fn interpret(response : HttpResponse) -> Response[Json] raise MegalodonError

#
multipart_file

fn multipart_file(boundary : String, field_name : String, file_name : String, mime_type : String, bytes : Bytes, fields? : Array[(String, String)]) -> MultipartBody raise MegalodonError

Build a deterministic multipart/form-data body without filesystem or clock access, keeping media upload available on every target.

#
pagination_from_headers

fn pagination_from_headers(headers : Map[String, String]) -> Pagination

#
percent_encode

fn percent_encode(text : String) -> String

RFC 3986 percent-encoding over UTF-8 bytes.

#
to_megalodon_error

fn to_megalodon_error(error : Error) -> MegalodonError

Powered by MoonBit

Site sourceReport issuePackagesBuild queueSkillsStatistics

© 2026 mooncakes.io