Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
Node is saved as draft in My Content >> Draft
  • Type of Response while making API

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 205
    Comment on it

    While making API you can have a different kind of response and you have to handle that for displaying data

    public IHttpActionResult GetDetails(string Id)
            {
                logger.Info("GetDetailsById method called");
    
               // BadRequest detected
    
                if (string.IsNullOrEmpty(Id))
                {
                    logger.Error("Id is empty");
                    return BadRequest("Id is empty!");
                }
    
                try
                {
                    var existing = DetailsDataOperations.GetPublicDetailsById(Id);
    
               // URL not found detected
    
                    if (existing == null)
                        return NotFound();
    
               // Everything goes fine then OK
    
                    logger.Info("GetDetailsById method completed");
                    return Ok(existingDetail);
                }
    
               // Internal server error gets detected
                catch (Exception ex)
                {
                    logger.Error(string.Format("Id : {0}",Id), ex);
                    return InternalServerError(ex);
                }
            }

    We use IHttpActionResult  class which contains definition of these return types
     

    .net

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: