项目作者: OKTAYKIR

项目描述 :
:package: Client framework for consuming JSONAPI services
高级语言: C#
项目地址: git://github.com/OKTAYKIR/jsonapi-consumer.git
创建时间: 2018-02-11T12:12:03Z
项目社区:https://github.com/OKTAYKIR/jsonapi-consumer

开源协议:MIT License

下载


JsonApi Client

Hits
GitHub issues
Build Status
PRs Welcome
nuget

Client framework for consuming JSONAPI web services based on the JSON API standard

:package: Installation

jsonapi-consumer is available on NuGet.

  1. dotnet add package jsonapi-consumer

🚀 Usage

Create HttpGet request with single response object

  1. Response<User[]> response = JsonApiConsumer.Get<User>(
  2. baseURI: ABSOLUTE_URL,
  3. path: RELATIVE_URI,
  4. query: new Dictionary<string, string>() { { "FirstName", "Oktay" }, { "LastName", "Kır" } },
  5. headers: new Dictionary<string, string>() { { HEADER_API_KEY, HEADER_API_KEY_VALUE } } );

Create HttpGet request with array response object

  1. Response<User> response = JsonApiConsumer.GetById<User>(
  2. id: "c833cbbf-7c81-4d30-b11a-88cf1c990b9c",
  3. baseURI: ABSOLUTE_URL,
  4. path: RELATIVE_URI,
  5. query: new Dictionary<string, string>() { { "FirstName", "Oktay" }, { "LastName", "Kır" } },
  6. headers: new Dictionary<string, string>() { { HEADER_API_KEY, HEADER_API_KEY_VALUE } } );

Create HttpPost request

  1. var user = new User()
  2. {
  3. id = "c833cbbf-7c81-4d30-b11a-88cf1c990b9c";
  4. FirstName = "Oktay";
  5. LastName="Kır";
  6. }
  7. Response<CreateUserResponse> response = JsonApiConsumer.Create<User, CreateUserResponse>(
  8. model: user,
  9. baseURI: ABSOLUTE_URL,
  10. path: RELATIVE_URI,
  11. headers: new Dictionary<string, string>() { { HEADER_API_KEY, HEADER_API_KEY_VALUE } } );

Post a file

  1. Response<PostFileResponse> response = JsonApiConsumer.PostFile<PostFileResponse>(
  2. fileName: "filename",
  3. data: new byte[],
  4. baseURI: ABSOLUTE_URL,
  5. path: RELATIVE_URI,
  6. headers: new Dictionary<string, string>() { { HEADER_API_KEY, HEADER_API_KEY_VALUE } } );

Create HttpPut request

  1. var user = new User()
  2. {
  3. FirstName = "Oktay";
  4. LastName="Kır";
  5. }
  6. Response<UpdateUserResponse> response = JsonApiConsumer.Update<User, UpdateUserResponse>(
  7. id: "c833cbbf-7c81-4d30-b11a-88cf1c990b9c",
  8. model: user,
  9. baseURI: ABSOLUTE_URL,
  10. path: RELATIVE_URI,
  11. headers: new Dictionary<string, string>() { { HEADER_API_KEY, HEADER_API_KEY_VALUE } } );

Create HttpPatch request

  1. var user = new User()
  2. {
  3. FirstName = "CC";
  4. }
  5. Response<PatchUserResponse> response = JsonApiConsumer.Patch<User, PatchUserResponse>(
  6. id: "c833cbbf-7c81-4d30-b11a-88cf1c990b9c",
  7. model: user,
  8. baseURI: ABSOLUTE_URL,
  9. path: RELATIVE_URI,
  10. headers: new Dictionary<string, string>() { { HEADER_API_KEY, HEADER_API_KEY_VALUE } } );

Create HttpDelete request

  1. Response<DeleteUserResponse> response = JsonApiConsumer.Delete<DeleteUserResponse>(
  2. id: "c833cbbf-7c81-4d30-b11a-88cf1c990b9c",
  3. baseURI: ABSOLUTE_URL,
  4. path: RELATIVE_URI,
  5. headers: new Dictionary<string, string>() { { HEADER_API_KEY, HEADER_API_KEY_VALUE } } );

Response class definition

  1. public class Response<T>
  2. {
  3. public DocumentRoot<T> documentRoot { get; internal set; }
  4. public HttpStatusCode httpStatusCode { get; internal set; }
  5. public Error error { get; set; }
  6. public bool IsSuccess { get; internal set; }
  7. }

✨ Contributors

GitHub Contributors Image

🤝 Contributing

  1. Fork it ( https://github.com/OKTAYKIR/jsonapi-consumer/fork )
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create a new Pull Request

Show your support

Please ⭐️ this repository if this project helped you!

📝 License

MIT License