How to Display Text in Browser using the Echo API ?


In some cases, you want to show some particular string in the browser after users click a hyperlink. You could design a simple API using PHP.

1
2
3
4
5
6
7
8
9
10
11
header("Access-Control-Allow-Origin: *");
header('Content-Type: text/plain');
$s = '';
if (isset($_GET['s'])) {
  $s = $_GET['s'];
} else {
  if (isset($_POST['s'])) {
    $s = $_POST['s'];
  }
}
die($s);
header("Access-Control-Allow-Origin: *");
header('Content-Type: text/plain');
$s = '';
if (isset($_GET['s'])) {
  $s = $_GET['s'];
} else {
  if (isset($_POST['s'])) {
    $s = $_POST['s'];
  }
}
die($s);

For example, the URL can be accessed via the following API: https://helloacm.com/api/echo/

You can pass the string via GET or POST and the parameter name is s. So for example, here is my bitcoin address (click to show in the browser).

API How to Display Text in Browser using the Echo API ? API php

Application Programming Interface

You could also change the content type to text/html if you want to support the basic HTML syntax e.g. headings, making text bold etc.

Call the Echo API via curl

1
curl -X POST "https://helloacm.com/api/echo/" -d "s=Hello"
curl -X POST "https://helloacm.com/api/echo/" -d "s=Hello"

The echo is now invoked remotely and what happens is that your machine sends the request to the server and the server returns the same message.

–EOF (The Ultimate Computing & Technology Blog) —

GD Star Rating
loading...
302 words
Last Post: The One-Line C# Linq Implementation of LineSpace Algorithm
Next Post: How to Implement and Unit Test LineSpace Algorithm in C++?

The Permanent URL is: How to Display Text in Browser using the Echo API ?

Leave a Reply