Uno: Create a tutorial how to consume webservices in UNO platform

Created on 30 Sep 2019  路  13Comments  路  Source: unoplatform/uno

What would you like clarification on:

Opening up GitHub issue to track this common request:

  1. How can I add web service in shared project?
  2. Can you please make a tutorial how to consume webservices in UNO platform?

Concern?

  • [ ] Usage in industry
  • [x] Clarification of capabilities
  • [x] Getting started with Uno
  • [x] Developing with Uno
  • [ ] Contributing to the Uno project
  • [ ] Publishing your application
  • [ ] Support
  • [ ] Other (please specify):

For which Platform:

  • [x] iOS
  • [x] Android
  • [x] WebAssembly
  • [ ] Windows

Anything else we need to know?

good first issue hacktoberfest help wanted projecdocumentation

Most helpful comment

@davidjohnoliver @agneszitte-nventive @ebariche I created a PR for the howto. The associated sample has been merged into the unoplatform/Uno.Samples repo here - TheCatApiClient

All 13 comments

re: web service in shared project

In Visual Studio, a shared project is just a list of files. Referencing a shared project in an ordinary .csproj project causes those files to be included in the project. They're treated in exactly the same way as the files inside the project.

It's important to be aware that the code in a shared-project file is compiled separately for each platform head. If you add a netstandard NuGet package such as Json.NET to a platform head and forget to add it to the other platform heads then those platform heads won't compile until you add the package.

Thus:

  1. Add any NuGet packages to each of your head projects
  2. Add the business logic for web service auth, fetching, domain model in your shared project.

re: tutorial how to consume webservices in UNO platform

Consumption of web-services (assuming http/json) in the Uno Platform works just the same as any .NET application. Use HttpClient or a library such as Refit.

If developing for for WebAssembly you'll need to create a WasmHttpHandler and then pass it in as the innerHandler of HttpClient.

#if __WASM__
            var innerHandler = new Uno.UI.Wasm.WasmHttpHandler();
#else
            var innerHandler = new HttpClientHandler();
#endif
            // please ensure that a single instance of _httpClient is used
            // between all requests.
            // https://aspnetmonsters.com/2016/08/2016-08-27-httpclientwrong/
            _httpClient = new HttpClient(innerHandler);

See https://github.com/anaselhajjaji/uno-platform-sample for an example using Refit.

See https://github.com/unoplatform/uado for an example using HttpClient.

GitHub
ample application that performs a REST API and shows a list of elements. This is to test UNO Platform. - anaselhajjaji/uno-platform-sample
GitHub
Universal Azure DevOps Organizer - Uno Reference Implementation project - unoplatform/uado

Please help me out with this i am able to understand the issue but don't know how to work on issues and how to add the tutorial, and also in which file should i contribute or make changes. Please help me i am new to the open source community.

@ghuntley I would like to work on this issue. Please assign this to me.

@greenorb007, welcome to GitHub. This might be too much for you to take on right now. I'd be happy to jump on a call to explain open-source/how GitHub works? https://ghuntley.com/meet

Calendly

@codetronaut it's yours!

@ghuntley Please tell me how should I start this, also should I write a separate blog for this or medium post or anything else?

@davidjohnoliver @ghuntley @agneszitte-nventive Is this issue still open? If so, I'd be happy to start working on it. In order to do so, I would like to know where I should create the markdown file, Any preferred style guide and if there is a defined structure for the file layout (I have a layout I use for Microsoft Labs which I could employ here).

My default layout would be:

H1: Tutorial title

Introductory content, what will be achieved (high-level tasks) and expected outcomes.

H2: Task _n_ - A title for the task

Brief description of the task.

(A numbered list of steps)

  1. In Visual Studio, to add a class for the web service, click ...
  1. In the New Item dialog, select Class*

...

H2: Summary

In this tutorial a web service implementation was added to the Uno Shared project. This implementation supports...

H2: References and next steps

(A bulleted list of references and other related tutorials, etc. Internal references first, then references to external Microsoft docs,etc.)

I have stubbed out the how-to here: How to consume webservices stub

@darenm This one is still open and would be a great contribution :)

The markdown file would go in https://github.com/unoplatform/uno/tree/master/doc/articles . You can add a link to the docfx table of contents (https://github.com/darenm/uno/blob/master/doc/articles/toc.yml#L64) so that it's listed in the docs website.

There's no explicit style guide for Uno docs - your layout looks good and is pretty close to the way the existing guides are structured.

If you create a working sample, you may wish to add it to the Uno.Samples repo (and link to it from the added guide).

GitHub
Build Mobile, Desktop and WebAssembly apps with C# and XAML. Today. Open source and professionally supported. - unoplatform/uno
GitHub
Build Mobile, Desktop and WebAssembly apps with C# and XAML. Today. Open source and professionally supported. - darenm/uno

@davidjohnoliver I just added a work sample to samples repo - https://github.com/unoplatform/Uno.Samples/pull/30

After doing so, I noticed that the CI expects the samples in the UI folder. What's the preference here? Move my sample or update the CI?

I have the how-to complete aside from the links to the sample.

Update: I moved the sample to the UI folder so the CI should run.

@davidjohnoliver @agneszitte-nventive @ebariche I created a PR for the howto. The associated sample has been merged into the unoplatform/Uno.Samples repo here - TheCatApiClient

Thanks a lot, @darenm for your help & contribution to this issue 馃憤 !

You're welcome. Any idea when the tutorial will be published?

You're welcome. Any idea when the tutorial will be published?

Thanks for the nudge @darenm ! Should be live now: https://platform.uno/docs/articles/howto-consume-webservices.html

Was this page helpful?
0 / 5 - 0 ratings

Related issues

MatFillion picture MatFillion  路  4Comments

MartinZikmund picture MartinZikmund  路  3Comments

chrisevans9629 picture chrisevans9629  路  4Comments

SuperJMN picture SuperJMN  路  3Comments

Ali-YousefiTelori picture Ali-YousefiTelori  路  4Comments