<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:media="http://search.yahoo.com/mrss/"><channel><title>2023-11 on Funky Si's Blog (Dev)</title><link>https://blog-dev.funkysi1701.com/2023/11/</link><description>Recent content in 2023-11 on Funky Si's Blog (Dev)</description><generator>Hugo -- gohugo.io</generator><language>en-gb</language><managingEditor>funkysi1701@gmail.com (Simon Foster)</managingEditor><webMaster>funkysi1701@gmail.com (Simon Foster)</webMaster><lastBuildDate>Sun, 19 Nov 2023 22:50:00 +0000</lastBuildDate><atom:link href="https://blog-dev.funkysi1701.com/2023/11/index.xml" rel="self" type="application/rss+xml"/><item><title>Make API calls from Visual Studio</title><link>https://blog-dev.funkysi1701.com/posts/2023/make-api-calls-from-visual-studio/</link><author>funkysi1701@gmail.com (funkysi1701)</author><pubDate>Sun, 19 Nov 2023 22:50:00 +0000</pubDate><guid>https://blog-dev.funkysi1701.com/posts/2023/make-api-calls-from-visual-studio/</guid><category term="VisualStudio">VisualStudio</category><category term="API">API</category><media:content medium="image" type="image/png" url="https://blog-dev.funkysi1701.com/images/endpoint-explorer.png"/><description>&lt;p&gt;It is that exciting time of year where Microsoft announce a new version of .Net (Version 8 this time) and Visual Studio. There have been lots of announcements which I am still digesting, but one that caught my eye was a new window in Visual Studio that shows all your API endpoints.&lt;/p&gt;
&lt;p&gt;The new window is called &lt;strong&gt;Endpoint Explorer&lt;/strong&gt; and can be added from the menu &lt;strong&gt;View &amp;gt; Other Windows &amp;gt; Endpoint Explorer&lt;/strong&gt;.&lt;/p&gt;
&lt;p&gt;
&lt;img class="img-fluid" alt="Endpoint Explorer" src="https://blog-dev.funkysi1701.com/images/endpoint-explorer.png" loading="lazy"
width="400" height="434"
/&gt;
&lt;/p&gt;
&lt;p&gt;If you right click on one of the endpoints you can view the code or send a request. It works with minimal APIs or standard MVC APIs. If you select send a request a .http file will be created, this is a feature that has been in Visual Studio for a while but I haven&amp;rsquo;t taken much notice.&lt;/p&gt;
&lt;p&gt;The syntax for writing these API calls is fairly simple&lt;/p&gt;
&lt;pre tabindex="0"&gt;&lt;code&gt;GET {{Catalog.API_HostAddress}}/api/v1/catalog/items
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Or something more complex, this one is a POST with a body and a header. This is how you might call APIs which require authentication. Just include a header with your auth token.&lt;/p&gt;
&lt;pre tabindex="0"&gt;&lt;code&gt;POST {{Catalog.API_HostAddress}}/api/v1/catalog/items
Accept: application/json
{
&amp;#34;name&amp;#34;: &amp;#34;Test&amp;#34;,
&amp;#34;description&amp;#34;: &amp;#34;Test&amp;#34;,
&amp;#34;price&amp;#34;: 1.99,
&amp;#34;pictureFileName&amp;#34;: &amp;#34;test.png&amp;#34;,
&amp;#34;pictureUri&amp;#34;: &amp;#34;https://picsum.photos/200/300&amp;#34;
}
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;You can also set up various variables at the top of your .http files by prefixing with an @, by default you get one that defines your base URL, but you can add more.&lt;/p&gt;
&lt;p&gt;eg @variable = value&lt;/p&gt;
&lt;p&gt;Full docs of how you use .http files can be found &lt;a href="https://learn.microsoft.com/en-us/aspnet/core/test/http-files?view=aspnetcore-8.0" target="_blank" rel="noopener noreferrer"&gt;here&lt;/a&gt;
&lt;/p&gt;
&lt;p&gt;A hyperlink above each API call in your .http file is labelled Send request. This initiates the API call and your window splits in half with the right hand side displaying the response.&lt;/p&gt;
&lt;p&gt;The response has four tabs, a nicely json formatted response, a raw response, a headers tab and a request tab.&lt;/p&gt;
&lt;p&gt;Now you will notice an env box underneath your file tabs, where the method dropdown is in a normal c# class file. It took me a while to figure out how to setup environments, but you can add a file that contain environment specific config, like base URL for test/prod/dev etc.&lt;/p&gt;
&lt;p&gt;This blog post tells me about it &lt;a href="https://devblogs.microsoft.com/visualstudio/safely-use-secrets-in-http-requests-in-visual-studio-2022/" target="_blank" rel="noopener noreferrer"&gt;here&lt;/a&gt;
but the main thing is you need to add a json file called &lt;strong&gt;http-client.env.json&lt;/strong&gt; and create some json like this:&lt;/p&gt;
&lt;pre tabindex="0"&gt;&lt;code&gt; &amp;#34;local&amp;#34;: {
&amp;#34;Api_HostAddress&amp;#34;: &amp;#34;http://localhost:44338&amp;#34;
},
&amp;#34;dev&amp;#34;: {
&amp;#34;Api_HostAddress&amp;#34;: &amp;#34;https://dev.example.com&amp;#34;
},
&amp;#34;test&amp;#34;: {
&amp;#34;Api_HostAddress&amp;#34;: &amp;#34;https://test.example.com&amp;#34;
},
&amp;#34;prod&amp;#34;: {
&amp;#34;Api_HostAddress&amp;#34;: &amp;#34;https://prod.example.com&amp;#34;
}
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Other environment specific variables can be added in the same way. Now you can easily call your API in different environments without having to change the URL each time.&lt;/p&gt;
&lt;h2 id="but-what-about-vs-code"&gt;But what about VS Code?&lt;a class="anchor ms-1" href="#but-what-about-vs-code" aria-label="Permalink: But what about VS Code?"&gt;&lt;i class="fas fa-link" aria-hidden="true"&gt;&lt;/i&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;Well it turns out that VS Code has a similar feature, but it is not enabled by default. You need to install the &lt;a href="https://marketplace.visualstudio.com/items?itemName=humao.rest-client" target="_blank" rel="noopener noreferrer"&gt;REST Client&lt;/a&gt;
extension. Once installed you can create a .http file and start making API calls. The syntax is very similar to Visual Studio.&lt;/p&gt;
&lt;p&gt;VS Code has a similar concept of environments. Go to Extensions &amp;gt; REST Client &amp;gt; Extension Settings and click on Edit in settings.json. Add the same settings we used with VS to your settings.json file. You can now switch environments from the command palette &amp;ldquo;Rest Client: Switch Environment&amp;rdquo; and select the environment you want to use.&lt;/p&gt;
&lt;p&gt;You can make use of the response of one API call in the request of another.&lt;/p&gt;
&lt;pre tabindex="0"&gt;&lt;code&gt;### 1st API Call
# @name login
POST {{Catalog.API_HostAddress}}/api/v1/identity/login
Content-Type: application/json
{
&amp;#34;user&amp;#34;: &amp;#34;username&amp;#34;,
&amp;#34;password&amp;#34;: &amp;#34;password&amp;#34;
}
### 2nd API Call
GET {{Catalog.API_HostAddress}}/api/v1/catalog/items
Authorization: Bearer {{login.response.body.token}}
Content-Type: application/json
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;The last feature of VS Code I want to mention is that it can make GQL calls.&lt;/p&gt;
&lt;pre tabindex="0"&gt;&lt;code&gt;POST {{Catalog.API_HostAddress}}/graphql
X-REQUEST-TYPE: GraphQL
Content-Type: application/json
Authorization: Bearer {{login.response.body.token}}
query ($name: String!, $owner: String!) {
repository(name: $name, owner: $owner) {
name
fullName: nameWithOwner
description
diskUsage
forkCount
stargazers(first: 5) {
totalCount
nodes {
login
name
}
}
watchers {
totalCount
}
}
}
{
&amp;#34;name&amp;#34;: &amp;#34;vscode-restclient&amp;#34;,
&amp;#34;owner&amp;#34;: &amp;#34;Huachao&amp;#34;
}
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Sorry postman but I think I have a new favourite tool for making API calls.&lt;/p&gt;</description></item><item><title>Be the best developer you can be</title><link>https://blog-dev.funkysi1701.com/posts/2023/become-the-best-actor-astronaut-or-developer-you-can-be/</link><author>funkysi1701@gmail.com (funkysi1701)</author><pubDate>Fri, 03 Nov 2023 01:00:00 +0000</pubDate><guid>https://blog-dev.funkysi1701.com/posts/2023/become-the-best-actor-astronaut-or-developer-you-can-be/</guid><category term="StarTrek">StarTrek</category><category term="PatrickStewart">PatrickStewart</category><category term="Goals">Goals</category><category term="JoseHernandez">JoseHernandez</category><category term="continuousimprovement">continuousimprovement</category><media:content medium="image" type="image/jpeg" url="https://blog-dev.funkysi1701.com/images/patrick-stewart.jpg"/><description>&lt;img src="https://blog-dev.funkysi1701.com/images/patrick-stewart.jpg" width="400px" style="float:left;padding-right:8px" alt="Patrick Stewart" /&gt;
&lt;p&gt;Recently I have been reading the first few chapters of Patrick Stewart&amp;rsquo;s Memoir, &lt;a href="https://www.amazon.co.uk/Making-It-So-A-Memoir/dp/B0C3VXDSGR/ref=sr_1_1" target="_blank" rel="noopener noreferrer"&gt;Making It So: A Memoir&lt;/a&gt;
. In it he tells the story of his early life. I find it fascinating that very early on it is quite clear he had a life goal. Become the best actor Patrick Stewart can be.&lt;/p&gt;
&lt;p&gt;Yes, there are other things in his life but this is what motivates much of what he does. At 12 he went on an 8 day residential drama course, where he met with like minded people that encourage him. So much that he continued to meet with them years after that course finished to grow his skills as an actor. This is something I would encourage everyone to do, find your tribe, find like minded people that will encourage you to grow and learn.&lt;/p&gt;
&lt;p&gt;After school he couldn&amp;rsquo;t see a future in acting professionally so took a job at a newspaper.  However when his job interfered with his acting in amateur dramatic groups, it caused him to reassess his priorities and he began saving to go to drama school. While at drama school he continued to improve and grow his acting skills. He has a singular vision in these early years to become an actor, and within a few weeks of finishing his training he had a job as an actor at a theatre. I have got up to the point where he is about to go on a world tour with a theatre group. During his first few jobs he continues to work on his acting skills. There is no doubt in my mind that this sense of continuous improvement helped mold Patrick Stewart into the actor we know today. While I am not a actor, I often think about continuous improvement, how can I be better at what I do.&lt;/p&gt;
&lt;img src="https://blog-dev.funkysi1701.com/images/million-miles.jpg" width="400px" style="float:right;padding-left:8px" alt="Promotional still from the film A Million Miles Away" /&gt;
&lt;p&gt;A film I saw recently has a similar tale of a singular vision. &lt;a href="https://www.amazon.co.uk/Million-Miles-Away-Michael-Pe%C3%B1a/dp/B0CC7MQFVD/ref=sr_1_1" target="_blank" rel="noopener noreferrer"&gt;A Million Miles Away&lt;/a&gt;
tells the story of Jose Hernandez, a man that wanted to be an Astronaut and applied to NASA 12 times (he was rejected 11 times!) He started life as a migrant farm worker, (so similar to Patrick Stewart who also grew up in poverty). He did everything in his power to achieve his goals, and didn&amp;rsquo;t give up.&lt;/p&gt;
&lt;p&gt;Jose Hernandez, when facing failure looked at those that had got into NASA. What did they have that he didn&amp;rsquo;t? He then worked on those areas to improve himself. He didn&amp;rsquo;t give up, he kept going. He works on his fitness, he got a pilots license, he learns Russian.&lt;/p&gt;
&lt;p&gt;So what&amp;rsquo;s my point. Have a Big Goal. It can be anything but it needs to be &lt;strong&gt;big&lt;/strong&gt;. My big goal of becoming a developer was achieved many years ago, and since then I have done a fair amount of drifting through life. What I need to do is be more like Patrick Stewart and continue to improve my skills, everyday make myself a better developer. What problems am I facing, lets break them down into manageable goals and get them solved so I can move on to the next lot.&lt;/p&gt;</description></item></channel></rss>