Web::M...Entity(3pm)

πŸ“¦
version 0.290 Β· 4 versions
, in ubuntu resolute, ubuntu stonking

πŸ’– Web::M...Entity πŸ’–

okay so bestie, this is Web::MREST::Entity, a chunk of the Perl user-contributed documentation, page 3pm. She's all about handling request entities and response entities β€” like, the actual stuff going in and out. she's lowkey iconic and you're gonna learn her. πŸŽ€


✨ NAME ✨

Web::MREST::Entity β€” Methods for dealing with request, response entities πŸ’…


🌸 SYNOPSIS 🌸

Methods for dealing with request, response entities

that's it. that's the synopsis. she's mysterious like that. ✨


πŸ¦‹ METHODS πŸ¦‹

get_acceptable_content_type_handler

so the method you use to process the request entity β€” aka the "acceptable content type handler" β€” gets set in content_types_accepted. here's the tea tho: Web::Machine only calls that method on PUT requests, and on those POST requests where post_is_create is true. πŸ™ˆ

but wait, what about the POST requests where post_is_create is false?? on those, we have to call it ourselves, bestie. no one else is coming to save us. and to do that, we need a way to actually get to it. that's literally this method. πŸ’€

content_types_provided

Web::Machine calls this routine to figure out how to generate the response body for GET requests. no cap. (and just so you know β€” it is not called for PUT, POST, or DELETE requests. she's exclusive. πŸ‘‘)

the return value has the following format:

[
    { 'text/html' => 'method_for_html' },
    { 'application/json' => 'method_for_json' },
    { 'other/mime' => 'method_for_other_mime' },
]

see how that's a list of tuples? the key is a media type and the value is the name of a method. and the vibe check here: the first tuple is taken as the default. so put your fave first, iykyk. 🫢

mrest_generate_response_html

normally, clients talk to the server via _render_response_json, but humans need HTML. we're not built different, we just need readability. 😭

this method takes the server's JSON response and wraps it up in a nice package β€” a little gift, if you will. 🎁 the return value from this method becomes the response entity. periodt.

content_types_accepted

Web::Machine calls this routine to determine how to handle the request body (e.g. in PUT requests). that's the whole job. she's efficient. πŸ’…

mrest_process_request_json

PUT and POST requests may contain a request body β€” and this right here is the "handler function" where we process those requests. slash slay.

we associate this function with 'application/json' via content_types_accepted. matching them up like a group chat flirt. πŸ’–

mrest_process_request

used to call the request handler manually in cases when Web::Machine does not call it for us. sometimes you gotta be your own main character. πŸ”₯

mrest_generate_response_json

okay this one is a whole three-step routine, let's go:

  1. first, run pass 2 of the resource handler, which is expected to return an App::CELL::Status object.
  2. second, push that object onto the context.
  3. third, convert that object into JSON and push the JSON onto the context, too. ✨

then return the JSON representation of the App::CELL::Status object β€” this becomes the HTTP response entity. and that's the whole ritual. πŸ•―οΈ

mrest_generate_response

this should somehow get the response handler and run it. that's the instruction, bestie. that's the whole thing. go get it and run it. πŸƒβ™€οΈπŸ’¨


🌈 and that's the page, fr fr. go forth and handle those entities. πŸ’œ

🧚 made with perl v5.40.1, dated 2025-06-21, straight from the User Contributed Perl Documentation. byeee bestie, mwah πŸ’…πŸŽ€πŸŒΈ

πŸ“¦ where this page comes from