Introduction to Edgelang

If you are looking for a powerful and efficient way to implement complex gateway logic, you might want to check out EdgeLang. EdgeLang is a domain-specific language created by OpenResty Inc. that lets you write concise and expressive rules for the OpenResty Edge product. OpenResty Edge is a traffic-management platform that provides various features such as page rules, web application firewall (WAF), load balancing, and many more. OpenResty Edge is almost completely built upon EdgeLang. Many high-traffic websites like Qunar, ADP, and Ajaib use EdgeLang to express their complex gateway and WAF needs.

Benefits of Edgelang

Why choose EdgeLang? Here are some of the benefits:

  • Performance: EdgeLang rules are compiled into highly optimized state machines that scan the input request data only once. This means that you can have multiple rules with complex conditions involving regular expressions and string patterns without sacrificing speed. EdgeLang rules are typically many times faster than hand-written Lua code, even with LuaJIT.

Embeded image

Embeded image

Embeded image

  • Safety: EdgeLang is a rule-based language that prevents common coding errors such as infinite loops, memory leaks, or undefined variables. You don’t have to worry about crashing your gateway or WAF with buggy code.
  • Flexibility: EdgeLang allows you to do a lot of things with simple and readable syntax. You can manipulate headers, cookies, query strings, body data, and more. You can also invoke custom Lua code or modules, or even C/C++ code if you need more functionality. EdgeLang works well with other OpenResty components such as ngx_lua and resty.core.
  • Maintainability: EdgeLang rules are easy to write and understand. They look like documentation rather than code. You can organize your rules into groups and apply them to different domains or paths. You can also use web-form-based page rules to create and manage your rules without writing any code.

The EdgeLang designer used to work at Cloudflare for years and I have seen how hard it is to maintain ad-hoc gateway logic written in Lua. EdgeLang is a much better alternative that offers more features and performance.

Edgelang in Edge Admin

In Edge Admin which is the web console of OpenResty Edge, we use Edgelang for various purposes, such as setting up page rules or WAF rules.

Embeded image

Embeded image

Conclusion

EdgeLang is a powerful and efficient way to implement complex gateway logic for the OpenResty Edge product. It offers many benefits such as performance, safety, flexibility, and maintainability. EdgeLang rules are easy to write and understand, and they work well with other OpenResty Edge features. You can use EdgeLang for various purposes such as page rules or WAF rules in Edge Admin. If you want to learn more about EdgeLang, you can read our comprehensive user manual on our documentation website. We hope you enjoy using EdgeLang and OpenResty Edge to create amazing web gateways or private CDN networks.

About The Author

Yichun Zhang (Github handle: agentzh), is the original creator of the OpenResty® open-source project and the CEO of OpenResty Inc..

Yichun is one of the earliest advocates and leaders of “open-source technology”. He worked at many internationally renowned tech companies, such as Cloudflare, Yahoo!. He is a pioneer of “edge computing”, “dynamic tracing” and “machine coding”, with over 22 years of programming and 16 years of open source experience. Yichun is well-known in the open-source space as the project leader of OpenResty®, adopted by more than 40 million global website domains.

OpenResty Inc., the enterprise software start-up founded by Yichun in 2017, has customers from some of the biggest companies in the world. Its flagship product, OpenResty XRay, is a non-invasive profiling and troubleshooting tool that significantly enhances and utilizes dynamic tracing technology. And its OpenResty Edge product is a powerful distributed traffic management and private CDN software product.

As an avid open-source contributor, Yichun has contributed more than a million lines of code to numerous open-source projects, including Linux kernel, Nginx, LuaJIT, GDB, SystemTap, LLVM, Perl, etc. He has also authored more than 60 open-source software libraries.