Re: Render custom status to both browser and REST API Client

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Saturday 25 February 2023 at 11:43:17, Kaushal Shriyan wrote:

> Hi,
> 
> Is there a way to configure apache httpd 2.4.55 as per the below flow when
> the below conditions occurs
> 
> User -> Apache Web Server -> PHP-FPM Upstream server -> MySQL DB
> 
> *Condition 1 when MySQL DB is down*
> When MySQL DB is down, httpd to render JSON output when invoking
> http://mydomain.com/apis by the user using postman rest api client.
> JSON Output
> {"status_code": 500, "status" : "MySQL DB Server is down"}
> 
> HTML Output
> HTML output when invoking http://mydomain.com/apis using client browser.

I just realised that you might be saying here "I want JSON output if the 
client sends a request from postman, and I want HTML output if it's from a 
browser, but in both cases the URL is the same".

To achieve that your CGI script simply needs to look at the User-Agent in the 
incoming request, and send back the appropriate format depending on whether 
it's postman or a browser.

I do not know offhand what the User-Agent string is for postman, but it can't 
be hard to find out.


Antony.

-- 
The GNU General Public Licence was first published on this day in 1989
https://www.gnu.org/licences/gpl.html

                                                   Please reply to the list;
                                                         please *don't* CC me.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@xxxxxxxxxxxxxxxx
For additional commands, e-mail: users-help@xxxxxxxxxxxxxxxx




[Index of Archives]     [Open SSH Users]     [Linux ACPI]     [Linux Kernel]     [Linux Laptop]     [Kernel Newbies]     [Security]     [Netfilter]     [Bugtraq]     [Squid]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Samba]     [Video 4 Linux]     [Device Mapper]

  Powered by Linux