What is the URL

I believe you are no stranger to URLS, especially for Web development students, almost every day with URLS. But do you really know what a URL is?

The URL is a Uniform Resource Locator (RFC1738**). ** At the Web level, used to locate the address of a given unique resource. The resource can be an HTML page, multimedia resource, JS file, and so on. At this point, you might have another question: How are urls put together?

http://www.joezou.com:80/about/me.html?userName=lucy&id=1#project
Copy the code
  • HTTP: indicates the communication protocol of a request. HTTP or HTTPS is usually used for web requests. It can also be a custom protocol.

  • www.joezou.com: domain name, which server to request, of course, can also be an IP address.

  • 80: indicates the port on which the access request server listens. For example, access through HTTP or HTTPS is ignored by default.

  • /about/me. HTML: path, which indicates the path to access resources on the server. In this case, the path is a file path or an interface path.

  • ? UserName = lucy&ID =1: parameter, an additional parameter to provide to the network server. These parameters are a list of key/value pairs separated by ampersand.

  • #project: anchor point, an anchor point for another part of the resource itself. An anchor represents a “bookmark” in a resource that gives the browser the direction of the content at that “bookmarked” location.

You have a basic understanding of urls. Both Dubbo and Dubbo-Go use urls to store data. But why use urls for a uniform data storage model? We’ll find out in a minute.

Why use urls

List, Map, and Set are common data structures used to store data. URL is a generic data structure that is often overlooked, but what about the data structure Dubbo chose as the data store?

Back to the beginning of the design, Dubbo, as a high-performance RPC framework, needs to use data that contains the following information.

  • Communication protocol

  • Host/Port

  • The name of the interface

  • Parameter key value pairs

At this point, does the URL mention at the beginning sound familiar? Therefore, THE URL was chosen as the data structure for the data store. So what are the pros and cons of using this data structure? The analysis phase is immediately followed.

The pros and cons of the URL

In addition to serving as a data structure for storing data, urls also serve as a model for conveying context information explicitly in programs. If there is no uniform data structure, you can only pass strings and assemble different structures. Causes the parameter list of the interface to change frequently as it is extended:

Register(host string,port int,path string) error
UnRegister(host string,port int,path string) error
Copy the code

If you decide to use the URL as the model for conveying context information.

Register(url \*common.URL) error
UnRegister(url \*common.URL) error
Copy the code

As a result, dubbo-Go’s various interfaces are flooded with such URL parameters. On top of this, the benefits are also obvious:

  • Model unification: Use a unified data structure from the parameters of the interface to the data store. It can simplify concepts, improve code readability, and form a unified code writing specification.

  • Scalability: Has very strong scalability. Data structures can be easily extended by simply following the URL specification. Interface parameters do not need to be modified.

  • High multi-language compatibility: almost all programming languages have methods that can deserialize URL strings. Out of the box.

As the saying goes, every advantage has its disadvantages.

  • High maintenance costs: Because extension is too easy, in the absence of a unified structured description document. As a result, it is not easy to find new/deleted parameters in multi-language situations. Therefore, maintaining uniform description documents can increase maintenance costs.

The last

Now that you understand why you need urls, the next chapter focuses on DESIGNING and applying urls. Understand urls more concretely with some practical examples.

Welcome to follow my technical public number

Join a community

In the public account background reply keyword [dubbogo] to join dubbo-go community.