0

Does anyone know why REST API does not support built-in error handling? I mean it's just an architectural pattern which can be implemented in a language. So how is it possible for a programming language not to handle errors?

GoldNeg
  • 1
  • 1
  • Programming languages and protocols don’t handle errors, they simply provide mechanisms by which the programmer can write code to raise and handle errors. Are you asking about the error handling capability of a specific library implementation or framework? – Dave M Oct 13 '18 at 14:33
  • My main issue is that why SOAP API supports built-in error handling and REST API doesn't? – GoldNeg Oct 13 '18 at 14:38
  • Those are basically protocols and as protocols they do both provide error mechanisms, at a most basic level, HTTP status codes. What is the name of the language and library or framework(s) you are using? What exactly are you having trouble with? – Dave M Oct 13 '18 at 14:41
  • @DaveM I'm doing a research on some ways of connection between client and server in c# winforms, and i'm comparing these two as web services. I wanted to know the reason behind this difference between them. – GoldNeg Oct 13 '18 at 14:47
  • This is not a difference between them. They both provide error mechanisms. Where did you get that information? – Dave M Oct 13 '18 at 14:52
  • @DaveM On a lot of websites :)) Maybe i've got the point in a wrong way. Since you called REST API a protocol, I also have to say that as i've been searching so far, REST API is not protocol, it's an architectural pattern. I'll be happy if you can make it clear for me. – GoldNeg Oct 13 '18 at 15:11
  • Well you are correct that it’s not exactly a protocol per se – Dave M Oct 13 '18 at 15:12
  • But it’s more than just an architecture, in practice – Dave M Oct 13 '18 at 15:14
  • Most while the REST concept does not specify it in particular, most REST services are based on HTTP (which is a protocol) and usually conform to a common set of conventions (which is the basic definition of a protocol). – Dave M Oct 13 '18 at 15:23

2 Answers2

1

Programming language (C# in this case) got its way dealing with errors (as I understand you're talking about exceptions). It's up to you in any architect, design..implementation to choose how to do this. Restful APIs mostly provide services to ease building the architecture like exposing dynamic urls, controlling the body requests easily..etc but exception handling is in the language and could be used as you like. Also HTTP errors mostly supported (common sense to say MUST here) to deliver them as responses to request as part or not of handling your errors. I think this question and answer would be good read for you.

Best practice to return errors in ASP.NET Web API

Mr. Om
  • 248
  • 2
  • 10
0

Which platform do you use ? asp.net mvc or .net core ? I you are using .net core here is sample code :

 public class Startup
 {
   public void Configure(IApplicationBuilder app, IHostingEnvironment env)
   {
     if (env.IsDevelopment() || env.IsStaging())
     {
         app.UseDeveloperExceptionPage();
     }

     app.Run(context => { throw new Exception("error"); });
   }
}
hsyn.ozkara
  • 117
  • 2
  • 11