Skip to content

Action filter for optionally wrapping a response in Jsend format

License

Notifications You must be signed in to change notification settings

mhlabs/Mhlabs.WebApi.JsendActionFilter

Repository files navigation

Mhlabs.WebApi.JsendActionFilter

Action filter for optionally wrapping a response in JSend format.

See https://labs.omniti.com/labs/jsend.

To enable, add the filter as middleware.

services.AddMvc(s =>
{
    s.AddJSendResponseFormat();
});

Example usage:

[HttpGet]
public ActionResult<bool> GetIt(string id, CancellationToken cancellationToken)
{
    if (string.IsNullOrWhiteSpace(id))
    {
        return this.Error("NO_ID", "Didn't get it.");
    }

    return true;
}

[HttpGet]
public async Task<DtoObject> Get(string id, CancellationToken cancellationToken)
{
    if (string.IsNullOrEmpty(id))
    {
        this.Fail("INVALID_ID", "Id is invalid");
    }

    var dto = await _handler.GetObject(id, cancellationToken);

    if (dto == null)
    {
        this.Fail("NOT_FOUND");
    }

    return dto;
}

Pushing a new version

Set the Version number in the .csproj-file before pushing. If an existing version is pushed the build will fail.

Publish pre-release packages on branches to allow us to test the package without merging to master

  1. Create a new branch
  2. Update Version number and add -beta postfix (can have .1, .2 etc. at the end)
  3. Make any required changes updating the version as you go
  4. Test beta package in solution that uses package
  5. Create PR and get it reviewed
  6. Check if there are any changes on the branch you're merging into. If there are you need to rebase those changes into yours and check that it still builds
  7. As the final thing before merging update version number and remove post fix

About

Action filter for optionally wrapping a response in Jsend format

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •  

Languages