简体   繁体   中英

A good way to implement a REST API in C#

We've to implement a REST API to access some features of our current server, which is written in C#. So, we'd like to expose some of its functionality (currently done through TCP) using a REST API.

Can you post some pointers to the right docs and ideas about how to get it implemented?

The server is not a "aspx" server but a service app.

For now primary REST technology in Microsoft stack is ASP.NET Web API http://www.asp.net/web-api (former WCF Web API)

Visit web site for ASP.NET Web API, there are a lot of tutorials on how to make it.

First I recommend to take a look at my different REST approach .

  • Don't use nested complex paths, keep it simple flat list of services and actions.
  • Don't use custom HTTP methods, use the path to specify the action.
  • Don't use custom HTTP error codes, that will mix your applicative errors with the HTTP protocol errors and will prevent complex error codes or partial success.
  • Support multi-request, which is multiple applicative requests in each HTTP request.

I also introduce simple C# simple REST server example for your convenience.

I have worked with a REST API in a project:

RestSharp is a simple, open source REST client for .NET designed primarily for consuming third-party HTTP APIs.

It took a lot of work out of my hands - i don't want to miss it ;-)

The Author of the Library John Sheehan is also on StackOverflow and usually helps really fast with specific problems!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM