Logo

dev-resources.site

for different kinds of informations.

Mezon wrapper for processing HTTP requests

Published at
12/31/2020
Categories
http
request
microservices
rest
Author
alexdodonov
Categories
4 categories in total
http
open
request
open
microservices
open
rest
open
Author
11 person written this
alexdodonov
open
Mezon wrapper for processing HTTP requests

This class will help you to fetch data from $_POST, $_GET arrays and headers.

Installation

Just print in console

composer require mezon/request
Enter fullscreen mode Exit fullscreen mode

And that's all )

Learn more

More information can be found here:

Twitter

dev.to

Slack

How to start

The firs steps are quite simple

var_dump(Request::getParam('some-param', 'default'));// will be outputted 'default'

$_GET['some-param'] = 'some-value';
var_dump(Request::getParam('some-param'));// will be outputted 'some-value'
Enter fullscreen mode Exit fullscreen mode

Fields priorities

In case you have the same parameters in $_GET, $_POST and other global arrays, then they will be prioritized in this way:

  • security tokens in HTTP headers
  • Router parameters
  • HTTP request headers
  • $_POST
  • $_GET

For example:

$_GET['some-param'] = 'get-value';
$_POST['some-param'] = 'post-value';

var_dump(Request::getParam('some-param'));// will be outputted 'post value'
Enter fullscreen mode Exit fullscreen mode

Router parameters

You can pass your Router object to this class and fetch parameters for non-static routes:

Request::registerRouter(<your Mezon\Router object>);
Enter fullscreen mode Exit fullscreen mode

Security tokens in HTTP headers

There are a way to fetch security token from headers:

  • Authentication
  • Authorization
  • Cgi-Authorization

For example if you will pass in headers something like that:

Authorization: Basic <some token>
Enter fullscreen mode Exit fullscreen mode

And then call:

Request::getParam('session_id')
Enter fullscreen mode Exit fullscreen mode

Then this call will return .

Wrappers

There are some convenient wrappers were implemented:

// will return true if the parameter exists
// will return false otherwise
Request::wasSubmitted('param-name')
Enter fullscreen mode Exit fullscreen mode

Or wrapper for check-boxes:

Request::getChecked('param-name', ['switched on', 'switched off'])
Request::getChecked('param-name', [1, 0])
Request::getChecked('param-name', [true, false])
Enter fullscreen mode Exit fullscreen mode

In this call the method getChecked will return the first element of the array which is passed as the second parameter. And the second element otherwise.

Learn more

More information can be found here:

Twitter
Mezon Framework

request Article's
30 articles in total
Favicon
important status code to be known as API developer
Favicon
HTTP Headers in API
Favicon
Mastering API Request Chaining: Essential Techniques for Developers
Favicon
Increasing API Reliability: Adding Timeouts to Node.js Fetch
Favicon
Python and APIs: how to use Python to connect and interact with APIs
Favicon
Rails Request specs with arbitrary JSON params
Favicon
Criando react hook personalizado para fazer requisiรงรตes
Favicon
HTTPS: Is it better than HTTP?
Favicon
Python: pytest accessing Flask session and request context variables.
Favicon
[HELP] Spring Boot: field is not set in request
Favicon
I'm Looking for Beta Readers
Favicon
An alternative API mocking library for frontend developers
Favicon
How to send request to join a organization in github
Favicon
Negotiating Languages with Ruby: A Journey through Linguistic Diversity
Favicon
Event-driven architecture over standard client-server aproach
Favicon
Roll your own Request object in Laravel
Favicon
Mezon wrapper for processing HTTP requests
Favicon
Preventing memory leak by handling errors and request cancellations separately in Axios
Favicon
How do you present a PR?
Favicon
How can i access the request object inside a nuxtJS module?
Favicon
React Js Axios Post Request Example Tutorial
Favicon
How to make API request from command line with CURL
Favicon
Request for Node.js has been deprecated
Favicon
NodeJS http homepage 20: request url with link menu
Favicon
Sharing the context with the model in an Express app
Favicon
A simple and useful #react component for helping with asynchronous loading/fetch data
Favicon
Feature request: @mention a user
Favicon
We want Dev.to REST API :)
Favicon
Perform small coding tasks for a reliable source of income?
Favicon
When to request data in SPA

Featured ones: