Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Writing API in C# for My Application

Tags:

c#

api

I'll write a application but I've never experienced to allow people to use my application programming interface before.I mean how kinda design I should make to let people use my methods from outside world like API.

Please some one show me a way.I am kinda new to this.

like image 211
Tarik Avatar asked Jul 22 '09 20:07

Tarik


People also ask

Can I use C for API?

C language API. The C language Application Programmer's Interface (API) allows application programs to submit faxes to the Zetafax server for sending, and to control and monitor their progress as required. A simple function call is provided to submit an ASCII text file in a given format.

What are APIs in C?

An application program interface (API) is code that allows two software programs to communicate with each other. An API defines the correct way for a developer to request services from an operating system (OS) or other application, and expose data within different contexts and across multiple channels.

Is C++ good for API?

For many C++ developers, API Design probably makes number 3 or 4 on their priority list. Majority of developers flock to C++ for the raw power and control it provides. Consequently, performance and optimization is what occupies the thoughts of these devs eighty percent of the time.

Can we write API in C++?

Normally yes. Generally: If source is to be available, use header only (if templates) or h +cpp. If no source, the best is DLL. Static libraries - you have to build for many compilers and one has to carry on your lib everywhere and link to it.


3 Answers

  1. Expose as little as you can. Every bit you publish, will return to you x100 in next version. Keeping compatibility is very hard.
  2. Create abstractions for everything you publish. You will definitely change your internals, but your existing users should stay compatible.
  3. Mark everything as internal. Even the main method of your application. Every single method that could be used, will be used.
  4. Test your public API the same way you would for interfaces. Integration tests and so on. Note that your API will be used in unpredictable ways.
  5. Maximize convention over configuration. This is required. Even if your API is a single method you will still need to support this. Just makes your life easier.
  6. Sign, and strong name your assemblies, this is good practice.
  7. Resolve as many FxCop and StyleCop errors as possible.
  8. Check your API is compatible with the Naming Guidelines of your platform.
  9. Provide as many examples as you can, and remember that most of the usage of your API will be Ctrl+C and Ctrl+V from these examples.
  10. Try to provide documentation. Check that you do not have GhostDoc-style auto-generated documentation. Everybody hates this.
  11. Include information on how to find you.
  12. Do not bother with obfuscation. This will help you and your users.

ADDED

  1. API should have as less dependencies as you can. For example, dependecies on the IoC containers should be prohibited. If your code uses it internally. Just ilmerge them into your assemblies.
like image 96
Mike Chaliy Avatar answered Sep 28 '22 06:09

Mike Chaliy


It may not be the funniest reading, and certainly not the only reading to do on the subject, but while designing your class library (your API), do check in with the Design Guidelines for Developing Class Libraries every now and then, it's a good idea to have a design that corresponds a bit with the .NET Framework iteself.

like image 26
Fredrik Mörk Avatar answered Sep 28 '22 08:09

Fredrik Mörk


Make your methods you want to expose to the outside world public.

like image 20
Paul Sonier Avatar answered Sep 28 '22 08:09

Paul Sonier