How to make a plugin run some code when a specific URL is accessed in the WP site


I have some custom code that I want to run.

I want it to run like this-->
(a) User visits
--> here I want the plugin's code to be invoked when the user visits "getdata" (or other URL slug)
(2) Now the plugin runs some code, and after that redirects the visitor to get some archived post data.

How do I do the above?