Host rules
This page describes how to use host rules in Advanced REST Client

What are the host rules?

Host rules assist your operating system to map a host name to an IP address. Historically it was used in first computers before first DNS (Domain Naming System) was created to tell the system what is the IP address of the remote machine while having it's name only. Today it is primarily used to alter host - IP address mapping to something different than DNS tells or to create a mapping that DNS is not aware of.

Why would you need it in ARC?

While developing a web server or an API often the server is run locally or in local network. In most cases IP address, that is well known to you, is enough to run a request. However sometimes you need to test a configuration that depends on the value of host header. This is quite common for servers that are hosting several virtual hosts.
Technically you can manually set the URL to an IP address and then put host header in the headers editor to test for virtual hosts. Other option is to alter system's hosts file to create a mapping but this usually requires administrative privileges. In ARC, however, recommended way of doing this is to define own hosts rules that maps parts of your URL to some other value, but keeps the original URL to generate a host header when connecting to a server.
When you define a rule and the rule matches the URL of currently executed request, the URL that is used to make a connection is replaced by the mapping value. This way, say, instead of connecting to you would be connecting to 127.0.0 (local host). However, when the HTTP message is constructed, the original URL value is used to set a value for host header which in this example will be host:

Defining rules

From the menu Request select Hosts. A host rules mapping screen appears. Click on the add button (right bottom corner of the screen) to add new entry.
Empty rule in hosts rules mapping
In the from filed enter the part of the URL that should be replaced with another value. It doesn't have to be a host name only. It can be a full URL or a part of it.
Defining a rule in hosts mapping editor
In this example the rules mapping maps to Notice that we are not only changing the host but also the scheme.
Now you can test whether the mapping meets your expectations by running a request URL through rules tester.
Rules tester with result
We are testing URL against defined rules. The result shows that expected result is
Now, we can run a request that uses in the URL and the connection is made to the local host.
Request made to mapped location
Even though the request URL contains non-existing URL the request returned data from my locally run server.
All rules are evaluated in order from the first one to the last one. Already altered URL can be altered again by another rule.


Host only mapping

From: To:
This will result with translating the following URL into

URI mapping

From: To:
This will result with translating the following URL into

With asterisk

From:*/ To: http://localhost/path/to/endpoint/
This will result with translating the following URL into http://localhost/path/to/endpoint/test?query=something.
Last modified 2yr ago