I have been doing programming, but now I’m facing a challenge. I’m on a project where I have to create an API in C# for my users. The basic process is that I have a C# code where I’m reading an XML file and obtaining the attributes and values that are between the tags. I achieved that and now I have to create consumable API for the same functionality.
Is there any way through which I can learn to create API?
Basically I dont have any idea on how to move on with API. Any sort of examples would be of good use to me.
An API is just a way for other programmers to interface with your code. A C# class library could be an API, as could a web service, a WCF endpoint, etc. The easiest way to make one is to create a C# Class Library project, make sure it has public methods, and compile it to a .dll which you can distribute.
As mentioned by others, the Framework Design Guidelines are useful for some rules to follow.
One thing to keep in mind – and I wish this would get hammered into all new software developers – is that API design is fundamentally a usability problem. You’re building a UI for the users of your software, and your users are other programmers.
This means that you want to follow all the general principals of UI/UX design – discoverability, making common tasks simple, etc.
Take advantage of XML comments to make sure the documentation is always there. Be sure that the most common tasks are easy to perform and that it’s obvious how to do so. Make exceptions clean and include useful, actionable error messages. Think about what would make the consumer’s life easier.