user3520332
user3520332

Reputation: 241

Constant Class for API Method Names

I am looking at a project that makes calls to an API (within C# code so this is taking place server-side). There are dozens of methods and so you might see something like /API/GetValue1 , /API/Search/ , /API/AnotherThing, or /API/Something/DoSomethingElse/1234411(some ID)

For all of this right now it's hard-coded into each of the calls, and likely won't change, but you never know.

Can all of this be moved into a constants class and so I could replace the occurence of /API/GetValue1 with something like MyConstantClass.Value1 and it would automatically put that as the URL path for the endpoint?

Upvotes: 2

Views: 1344

Answers (1)

Toan Nguyen
Toan Nguyen

Reputation: 11601

That's what you should do. Create a static class to contain all of your API endpoints. Never use magic strings directly in code, because they are error-prone.

Upvotes: 1

Related Questions