├── App.config ├── packages.config ├── Pokemon.cs ├── Flurl-Sample.sln ├── LICENSE ├── Properties └── AssemblyInfo.cs ├── Flurl-Sample.csproj ├── Program.cs └── .gitignore /App.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /packages.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /Pokemon.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | using Newtonsoft.Json; 7 | 8 | namespace Flurl_Sample 9 | { 10 | public class Pokemon 11 | { 12 | public int Id { get; set; } 13 | public string Name { get; set; } 14 | 15 | [JsonProperty("base_experience")] 16 | public int BaseExperience { get; set; } 17 | public int Height { get; set; } 18 | 19 | 20 | [JsonProperty("is_default")] 21 | public bool IsDefault { get; set; } 22 | public int Order { get; set; } 23 | public int Weight { get; set; } 24 | public List Abilities { get; set; } 25 | } 26 | 27 | public class PokemonAbility 28 | { 29 | [JsonProperty("is_hidden")] 30 | public bool IsHidden { get; set; } 31 | public int Slot { get; set; } 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /Flurl-Sample.sln: -------------------------------------------------------------------------------- 1 | 2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 2013 4 | VisualStudioVersion = 12.0.40629.0 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Flurl-Sample", "Flurl-Sample.csproj", "{F58CBB51-4E04-4C18-B06D-A3F015178E53}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|Any CPU = Debug|Any CPU 11 | Release|Any CPU = Release|Any CPU 12 | EndGlobalSection 13 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 14 | {F58CBB51-4E04-4C18-B06D-A3F015178E53}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 15 | {F58CBB51-4E04-4C18-B06D-A3F015178E53}.Debug|Any CPU.Build.0 = Debug|Any CPU 16 | {F58CBB51-4E04-4C18-B06D-A3F015178E53}.Release|Any CPU.ActiveCfg = Release|Any CPU 17 | {F58CBB51-4E04-4C18-B06D-A3F015178E53}.Release|Any CPU.Build.0 = Release|Any CPU 18 | EndGlobalSection 19 | GlobalSection(SolutionProperties) = preSolution 20 | HideSolutionNode = FALSE 21 | EndGlobalSection 22 | EndGlobal 23 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2016 That C# Guy 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyTitle("Flurl-Sample")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("")] 12 | [assembly: AssemblyProduct("Flurl-Sample")] 13 | [assembly: AssemblyCopyright("Copyright © 2016")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // Setting ComVisible to false makes the types in this assembly not visible 18 | // to COM components. If you need to access a type in this assembly from 19 | // COM, set the ComVisible attribute to true on that type. 20 | [assembly: ComVisible(false)] 21 | 22 | // The following GUID is for the ID of the typelib if this project is exposed to COM 23 | [assembly: Guid("f087ed9f-27a2-4957-8f8e-fda468a45e9c")] 24 | 25 | // Version information for an assembly consists of the following four values: 26 | // 27 | // Major Version 28 | // Minor Version 29 | // Build Number 30 | // Revision 31 | // 32 | // You can specify all the values or you can default the Build and Revision Numbers 33 | // by using the '*' as shown below: 34 | // [assembly: AssemblyVersion("1.0.*")] 35 | [assembly: AssemblyVersion("1.0.0.0")] 36 | [assembly: AssemblyFileVersion("1.0.0.0")] 37 | -------------------------------------------------------------------------------- /Flurl-Sample.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Debug 6 | AnyCPU 7 | {F58CBB51-4E04-4C18-B06D-A3F015178E53} 8 | Exe 9 | Properties 10 | Flurl_Sample 11 | Flurl-Sample 12 | v4.5 13 | 512 14 | 15 | 16 | AnyCPU 17 | true 18 | full 19 | false 20 | bin\Debug\ 21 | DEBUG;TRACE 22 | prompt 23 | 4 24 | 25 | 26 | AnyCPU 27 | pdbonly 28 | true 29 | bin\Release\ 30 | TRACE 31 | prompt 32 | 4 33 | 34 | 35 | 36 | packages\Flurl.1.1.2\lib\portable-net40+sl50+win+wpa81+wp80+MonoAndroid10+MonoTouch10\Flurl.dll 37 | True 38 | 39 | 40 | packages\Flurl.Http.0.9.0\lib\net45\Flurl.Http.dll 41 | True 42 | 43 | 44 | packages\Newtonsoft.Json.6.0.3\lib\net45\Newtonsoft.Json.dll 45 | True 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 73 | -------------------------------------------------------------------------------- /Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Net; 5 | using System.Text; 6 | using System.Threading.Tasks; 7 | using Flurl; 8 | using Flurl.Http; 9 | 10 | namespace Flurl_Sample 11 | { 12 | class Program 13 | { 14 | static void Main(string[] args) 15 | { 16 | var mainAsync = MainAsync(args); 17 | mainAsync.Wait(); 18 | } 19 | 20 | static async Task MainAsync(string[] args) 21 | { 22 | Console.WriteLine("=> Url building stuff:\n"); 23 | 24 | var myCoolUrl1 = "http://localhost/" 25 | .AppendPathSegment("sales") 26 | .AppendPathSegment("Q1"); 27 | Console.WriteLine(myCoolUrl1); 28 | 29 | var myCoolUrl2 = "http://localhost/" 30 | .AppendPathSegment("sales") 31 | .AppendPathSegment("Q1") 32 | .AppendPathSegment("max"); 33 | Console.WriteLine(myCoolUrl2); 34 | 35 | // From an array 36 | var urlParts = new string[] { "liga_mx", "results", "america" }; 37 | var builtUrl = new Url("http://api.soccer-data.com"); 38 | foreach (var urlPart in urlParts) 39 | { 40 | builtUrl.AppendPathSegment(urlPart); 41 | } 42 | Console.WriteLine(builtUrl); 43 | 44 | // Single method 45 | var builtUrl2 = new Url("http://api.soccer-data.com"); 46 | builtUrl2.AppendPathSegments(urlParts); 47 | Console.WriteLine(builtUrl2); 48 | 49 | // Add query string parameters 50 | var endDate = DateTime.Today; 51 | var startDate = endDate.AddDays(-30); 52 | var competition = "concacaf champions league"; 53 | builtUrl.SetQueryParams(new { endDate, startDate, c = competition }); 54 | Console.WriteLine(builtUrl); 55 | 56 | // Remove query string params 57 | builtUrl.RemoveQueryParams("c", "startDate"); 58 | Console.WriteLine(builtUrl); 59 | 60 | 61 | Console.WriteLine("\n=> Http client stuff:\n"); 62 | var client = myCoolUrl1 63 | .WithBasicAuth("antonio", "secretPass") 64 | .WithHeader("User-Agent", "Flurl-Sample"); 65 | 66 | var httpClient = client.HttpClient; 67 | Console.WriteLine(httpClient.DefaultRequestHeaders); 68 | 69 | var client2 = builtUrl 70 | .WithOAuthBearerToken("t0k3n") 71 | .WithHeader("Accept-Language", "it") 72 | .WithHeader("User-Agent", "Flurl-Sample") 73 | .WithHeaders(new 74 | { 75 | CustomHeader = "Another value", 76 | Accept = "text/json" 77 | }); 78 | var httpClient1 = client2.HttpClient; 79 | Console.WriteLine(httpClient1.DefaultRequestHeaders); 80 | 81 | 82 | Console.WriteLine("\n=> Http requests stuff:\n"); 83 | 84 | // "Real" example: 85 | 86 | var pokemonId = 25; 87 | var url1 = "http://pokeapi.co/api/v2/" 88 | .AppendPathSegment("pokemon") 89 | .AppendPathSegment(pokemonId.ToString()); 90 | 91 | Console.WriteLine("Consultando " + url1); 92 | 93 | // Realiza la petición HTTP: 94 | dynamic pkmn1 = await url1.GetJsonAsync(); // pkmn1 95 | Console.WriteLine(pkmn1.name + " " + "\nH:" + pkmn1.height + "\nW:" + pkmn1.weight + "\n"); 96 | 97 | // Cambia el nombre por otro pokemon para obtener un error 98 | var pokemonName = "charmander"; 99 | try 100 | { 101 | // Construcción de la URL 102 | var url2 = "http://pokeapi.co/api/v2/" 103 | .AppendPathSegments("pokemon", pokemonName); 104 | 105 | Console.WriteLine("Consultando " + url2); 106 | 107 | // Realiza la petición HTTP: 108 | var pokemon = await url2.GetJsonAsync(); 109 | Console.WriteLine(pokemon.Name + "\nH:" + pokemon.Height + "\nW:" + pokemon.Weight + "\n"); 110 | 111 | } 112 | catch (FlurlHttpException ex) 113 | { 114 | if (ex.Call.Response != null 115 | && ex.Call.Response.StatusCode == HttpStatusCode.NotFound) 116 | { 117 | Console.WriteLine("No existe un pokemon llamado " + pokemonName); 118 | } 119 | } 120 | Console.Read(); 121 | } 122 | 123 | } 124 | } 125 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | 2 | # Created by https://www.gitignore.io/api/visualstudio,windows,osx,xamarinstudio 3 | 4 | ### VisualStudio ### 5 | ## Ignore Visual Studio temporary files, build results, and 6 | ## files generated by popular Visual Studio add-ons. 7 | 8 | # User-specific files 9 | *.suo 10 | *.user 11 | *.userosscache 12 | *.sln.docstates 13 | 14 | # User-specific files (MonoDevelop/Xamarin Studio) 15 | *.userprefs 16 | 17 | # Build results 18 | [Dd]ebug/ 19 | [Dd]ebugPublic/ 20 | [Rr]elease/ 21 | [Rr]eleases/ 22 | x64/ 23 | x86/ 24 | bld/ 25 | [Bb]in/ 26 | [Oo]bj/ 27 | [Ll]og/ 28 | 29 | # Visual Studio 2015 cache/options directory 30 | .vs/ 31 | # Uncomment if you have tasks that create the project's static files in wwwroot 32 | #wwwroot/ 33 | 34 | # MSTest test Results 35 | [Tt]est[Rr]esult*/ 36 | [Bb]uild[Ll]og.* 37 | 38 | # NUNIT 39 | *.VisualState.xml 40 | TestResult.xml 41 | 42 | # Build Results of an ATL Project 43 | [Dd]ebugPS/ 44 | [Rr]eleasePS/ 45 | dlldata.c 46 | 47 | # DNX 48 | project.lock.json 49 | artifacts/ 50 | 51 | *_i.c 52 | *_p.c 53 | *_i.h 54 | *.ilk 55 | *.meta 56 | *.obj 57 | *.pch 58 | *.pdb 59 | *.pgc 60 | *.pgd 61 | *.rsp 62 | *.sbr 63 | *.tlb 64 | *.tli 65 | *.tlh 66 | *.tmp 67 | *.tmp_proj 68 | *.log 69 | *.vspscc 70 | *.vssscc 71 | .builds 72 | *.pidb 73 | *.svclog 74 | *.scc 75 | 76 | # Chutzpah Test files 77 | _Chutzpah* 78 | 79 | # Visual C++ cache files 80 | ipch/ 81 | *.aps 82 | *.ncb 83 | *.opendb 84 | *.opensdf 85 | *.sdf 86 | *.cachefile 87 | *.VC.db 88 | *.VC.VC.opendb 89 | 90 | # Visual Studio profiler 91 | *.psess 92 | *.vsp 93 | *.vspx 94 | *.sap 95 | 96 | # TFS 2012 Local Workspace 97 | $tf/ 98 | 99 | # Guidance Automation Toolkit 100 | *.gpState 101 | 102 | # ReSharper is a .NET coding add-in 103 | _ReSharper*/ 104 | *.[Rr]e[Ss]harper 105 | *.DotSettings.user 106 | 107 | # JustCode is a .NET coding add-in 108 | .JustCode 109 | 110 | # TeamCity is a build add-in 111 | _TeamCity* 112 | 113 | # DotCover is a Code Coverage Tool 114 | *.dotCover 115 | 116 | # NCrunch 117 | _NCrunch_* 118 | .*crunch*.local.xml 119 | nCrunchTemp_* 120 | 121 | # MightyMoose 122 | *.mm.* 123 | AutoTest.Net/ 124 | 125 | # Web workbench (sass) 126 | .sass-cache/ 127 | 128 | # Installshield output folder 129 | [Ee]xpress/ 130 | 131 | # DocProject is a documentation generator add-in 132 | DocProject/buildhelp/ 133 | DocProject/Help/*.HxT 134 | DocProject/Help/*.HxC 135 | DocProject/Help/*.hhc 136 | DocProject/Help/*.hhk 137 | DocProject/Help/*.hhp 138 | DocProject/Help/Html2 139 | DocProject/Help/html 140 | 141 | # Click-Once directory 142 | publish/ 143 | 144 | # Publish Web Output 145 | *.[Pp]ublish.xml 146 | *.azurePubxml 147 | # TODO: Comment the next line if you want to checkin your web deploy settings 148 | # but database connection strings (with potential passwords) will be unencrypted 149 | *.pubxml 150 | *.publishproj 151 | 152 | # Microsoft Azure Web App publish settings. Comment the next line if you want to 153 | # checkin your Azure Web App publish settings, but sensitive information contained 154 | # in these scripts will be unencrypted 155 | PublishScripts/ 156 | 157 | # NuGet Packages 158 | *.nupkg 159 | # The packages folder can be ignored because of Package Restore 160 | **/packages/* 161 | # except build/, which is used as an MSBuild target. 162 | !**/packages/build/ 163 | # Uncomment if necessary however generally it will be regenerated when needed 164 | #!**/packages/repositories.config 165 | # NuGet v3's project.json files produces more ignoreable files 166 | *.nuget.props 167 | *.nuget.targets 168 | 169 | # Microsoft Azure Build Output 170 | csx/ 171 | *.build.csdef 172 | 173 | # Microsoft Azure Emulator 174 | ecf/ 175 | rcf/ 176 | 177 | # Windows Store app package directories and files 178 | AppPackages/ 179 | BundleArtifacts/ 180 | Package.StoreAssociation.xml 181 | _pkginfo.txt 182 | 183 | # Visual Studio cache files 184 | # files ending in .cache can be ignored 185 | *.[Cc]ache 186 | # but keep track of directories ending in .cache 187 | !*.[Cc]ache/ 188 | 189 | # Others 190 | ClientBin/ 191 | ~$* 192 | *~ 193 | *.dbmdl 194 | *.dbproj.schemaview 195 | *.pfx 196 | *.publishsettings 197 | node_modules/ 198 | orleans.codegen.cs 199 | 200 | # Since there are multiple workflows, uncomment next line to ignore bower_components 201 | # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) 202 | #bower_components/ 203 | 204 | # RIA/Silverlight projects 205 | Generated_Code/ 206 | 207 | # Backup & report files from converting an old project file 208 | # to a newer Visual Studio version. Backup files are not needed, 209 | # because we have git ;-) 210 | _UpgradeReport_Files/ 211 | Backup*/ 212 | UpgradeLog*.XML 213 | UpgradeLog*.htm 214 | 215 | # SQL Server files 216 | *.mdf 217 | *.ldf 218 | 219 | # Business Intelligence projects 220 | *.rdl.data 221 | *.bim.layout 222 | *.bim_*.settings 223 | 224 | # Microsoft Fakes 225 | FakesAssemblies/ 226 | 227 | # GhostDoc plugin setting file 228 | *.GhostDoc.xml 229 | 230 | # Node.js Tools for Visual Studio 231 | .ntvs_analysis.dat 232 | 233 | # Visual Studio 6 build log 234 | *.plg 235 | 236 | # Visual Studio 6 workspace options file 237 | *.opt 238 | 239 | # Visual Studio LightSwitch build output 240 | **/*.HTMLClient/GeneratedArtifacts 241 | **/*.DesktopClient/GeneratedArtifacts 242 | **/*.DesktopClient/ModelManifest.xml 243 | **/*.Server/GeneratedArtifacts 244 | **/*.Server/ModelManifest.xml 245 | _Pvt_Extensions 246 | 247 | # Paket dependency manager 248 | .paket/paket.exe 249 | paket-files/ 250 | 251 | # FAKE - F# Make 252 | .fake/ 253 | 254 | # JetBrains Rider 255 | .idea/ 256 | *.sln.iml 257 | 258 | 259 | ### Windows ### 260 | # Windows image file caches 261 | Thumbs.db 262 | ehthumbs.db 263 | 264 | # Folder config file 265 | Desktop.ini 266 | 267 | # Recycle Bin used on file shares 268 | $RECYCLE.BIN/ 269 | 270 | # Windows Installer files 271 | *.cab 272 | *.msi 273 | *.msm 274 | *.msp 275 | 276 | # Windows shortcuts 277 | *.lnk 278 | 279 | 280 | ### OSX ### 281 | .DS_Store 282 | .AppleDouble 283 | .LSOverride 284 | 285 | # Icon must end with two \r 286 | Icon 287 | 288 | 289 | # Thumbnails 290 | ._* 291 | 292 | # Files that might appear in the root of a volume 293 | .DocumentRevisions-V100 294 | .fseventsd 295 | .Spotlight-V100 296 | .TemporaryItems 297 | .Trashes 298 | .VolumeIcon.icns 299 | 300 | # Directories potentially created on remote AFP share 301 | .AppleDB 302 | .AppleDesktop 303 | Network Trash Folder 304 | Temporary Items 305 | .apdisk 306 | 307 | 308 | ### XamarinStudio ### 309 | bin/ 310 | obj/ 311 | *.userprefs 312 | --------------------------------------------------------------------------------