question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Retrieving the full request URL

See original GitHub issue

Is your feature request related to a problem? Please describe. Actually, I can get the current path with request.path. It would be great to add:

  • request.url with the full request without the query string. Ex: http://example.com
  • request.full_url with the full request with the query string. Ex: http://example.com?q=search

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:5 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
nokcommented, May 26, 2020

Yes, please! It’s a good idea and suggestion.

I think that a developer expects these information from a passed request. But we should’t reinvent the wheel. What do you think about furl? It’s flexible and well tested.

Usage:

# app/http/controllers/HelloWorldController.py

"""A HelloWorldController Module."""

from masonite.response import Response
from masonite.request import Request
from masonite.controllers import Controller


class HelloWorldController(Controller):
    """HelloWorldController Controller Class."""

    def show(self, request: Request, response: Response):
        furl = request.furl.asdict()
        return response.json(furl)

Response:

{
    "fragment": {
        "encoded": "",
        "path": {
            "encoded": "",
            "isabsolute": [],
            "isdir": true,
            "isfile": false,
            "segments": []
        },
        "query": {
            "encoded": "",
            "params": []
        },
        "separator": true
    },
    "host": "localhost",
    "host_encoded": "localhost",
    "netloc": "localhost:8000",
    "origin": "http://localhost:8000",
    "password": null,
    "path": {
        "encoded": "/hello",
        "isabsolute": true,
        "isdir": false,
        "isfile": true,
        "segments": [
            "hello"
        ]
    },
    "port": 8000,
    "query": {
        "encoded": "",
        "params": []
    },
    "scheme": "http",
    "url": "http://localhost:8000/hello",
    "username": null
}

Implementation:

# masonite/request.py


from furl import furl
# [...]

class Request(Extendable):
    # [...]

    @property
    def furl(self) -> furl.furl:
        full_url = self.environ.get('APP_URL') + self.path  # <--- here we have to pass the full url
        return furl(full_url)

We can use this blueprint as a starting point.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Get the full URL in PHP - Stack Overflow
I use this code to get the full URL: $actual_link = 'http://'.$_SERVER['HTTP_HOST'].$_SERVER['PHP_SELF'];
Read more >
Get the full URL in PHP - GeeksforGeeks
Get the full URL in PHP · Create a PHP variable that will store the URL in string format. · Check whether the...
Read more >
Get The Full Requested URL in PHP - Beamtic
To get the full requested URL you can use a combination of $_SERVER variables to "guess" the URL—a quick example of how to...
Read more >
How to get current page URL in PHP? - Javatpoint
Learn simple PHP program; it will help you find current page URL. You can get the full URL or only name of the...
Read more >
GET a url. - httr
The GET method means retrieve whatever information (in the form of an entity) is identified by the Request-URI. If the Request-URI refers to...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found