Request for example code for "beginners"?
There is already a huge list providing implementations for several languages where you can read through over here: https://forum-en.gw2archive.eu/forum/community/api/API-implementation-library-master-list/2068146
Anyway, the most common steps are:
- send a HTTP GET request to the url of the desired API
- recieve the response
- parse the response JSON
- use the data
Milage may vary between programming languages. You may also want to cache the data which you receive from several requests like e.g. the world names to reduce the amount of requests you send since they’re static anyway.
(edited by smiley.1438)
As you are developing in C#/Asp.Net you could use GW2.NET to have wrapper around the API.
Why reinvent the wheel if you can get one for free
Why reinvent the wheel if you can get one for free
Because it’s fun and since I specifically tailored my wheel, it has a perfect fit. There’s no point in having snow tires if it’ll never snow.
(smaller, faster and more efficient)
For a beginner, don’t just use wrappers, learn from them. Don’t skip the basics, which will include reinventing the wheel. For example, if I ask a javascript developer how to get a JSON response and their only answer is getJSON(), they’ve failed.
Why reinvent the wheel if you can get one for free
Because it’s fun
That’s exactly why I wrote my Perl module, even though everyone else uses PHP or Python for script-monkeying these days.
I would recommend using GW2.Net or GwSharp’s API and break it apart. Look into it, write console applications that display the information you want. Modify the API to display information in a different way.
A pretty nice exercise for myself was to take GW2Stuff’s overlay source code and change it to display WvW information using GwSharp. Nice crash course on how to deal with information and threads.
keep in mind, the API is for building external applications or websites that pull data from the GW2 databases. it’s not for for making in-game addons.
-ken
That’s exactly why I wrote my Perl module,
Well that’s something different. If I’d code in C# and there are only c++ wrapper around I’d write something for myself. That’s not reinventing the wheel.
On the other hand if there are already five c# implementations out there I’d probably grab one of those, since it’s far less time consuming.
@Steckums: GW2.Net also has an WvW implementation (and I might add a more complete one)
Yes I agree with Ruhrpottpatriot, I would recommend using a well-tested library if development time is a factor.
But if you are doing this for your own edification and you want to learn technologies like JSON.NET or RestSharp, etc. which could be transferable to other similar projects, then I would agree with Healix and recommend that you learn from existing libraries to implement your own library.
(edited by DarkSpirit.7046)
yeah if you want to learn something then it’s better to write your own implementation
I"m not even sure how to use a wrapper, but I see your point ;-) I’m going to start messing with it tomorrow evening and will hopefully be able to make something simple. Thanks for the advice, everyone!
If you don’t want to use any wrappers,, have a look at this:
https://forum-en.gw2archive.eu/forum/community/api/Simple-C-Example-Rating-Calculation
It’s C#, it doesn’t use any wrappers or libraries except what .NET 2.0 comes with, and it has been updated with more comments to make it a little bit more beginner-friendly.
If nothing else, it will show you the basic mechanism to invoke the API and process the results.
-ken
If you’re new to API programming, I highly recommend this list of free courses on Codecademy. I learned most of what I know about interacting with APIs through JavaScript from those courses. Highly recommended if you’re just starting out!