### Install FSharp.Data using NuGet
Source: https://context7.com/fsprojects/fsharp.data/llms.txt
Reference the FSharp.Data NuGet package in your F# scripts or projects.
```fsharp
#r "nuget: FSharp.Data"
open FSharp.Data
```
```xml
```
--------------------------------
### Watch Documentation Changes
Source: https://github.com/fsprojects/fsharp.data/blob/main/CONTRIBUTING.md
Run this command to start a local file watcher that regenerates and serves documentation. Changes are reflected in the browser automatically.
```console
dotnet fsdocs watch
```
--------------------------------
### Release Notes Format
Source: https://github.com/fsprojects/fsharp.data/blob/main/AGENTS.md
Example format for updating release notes. Follow this structure when documenting user-facing changes for a new release.
```markdown
## X.Y.Z - Date
- Description of change by @author in #PR
```
--------------------------------
### GET Request with Query Parameters and Custom Headers
Source: https://context7.com/fsprojects/fsharp.data/llms.txt
Makes an HTTP GET request with specified query parameters and custom headers, such as Accept and User-Agent. Useful for interacting with APIs that require specific request configurations.
```F#
open FSharp.Data
open FSharp.Data.HttpRequestHeaders
let json =
Http.RequestString(
"https://api.github.com/repos/fsprojects/FSharp.Data/releases",
query = [ "per_page", "5" ],
headers = [ Accept HttpContentTypes.Json; UserAgent "MyApp" ])
```
--------------------------------
### Add New Benchmark Method
Source: https://github.com/fsprojects/fsharp.data/blob/main/tests/FSharp.Data.Benchmarks/README.md
Example of how to add a new benchmark method in F#. Mark methods with the `[]` attribute and use `[]` for initialization if needed.
```fsharp
[]
member this.MyNewBenchmark() =
// Your code to benchmark here
SomeOperation()
```
--------------------------------
### Ad Initialization and Monitoring Setup
Source: https://github.com/fsprojects/fsharp.data/blob/main/tests/FSharp.Data.Tests/Data/imdb_chart.htm
Executes ad initialization logic, sets up monitoring metrics, and configures ad slots. This function is called within the `doWithAds` wrapper.
```javascript
doWithAds(function () {
generic.monitoring.record_metric("ads_js_request_to_done", (new Date().getTime()) - window.ads_js_start);
ad_utils.weblab.set_treatment('gpt single-request', 'Use GPT ad requests.');
generic.monitoring.enable_weblab_metrics('107', '2', [
'csm_core_ads_load',
'csm_core_ads_iframe',
'csm_core_ads_reflow',
'csm_core_ads_tagdeliver',
'csm_core_ads_request',
'csm_top_ad_load',
'csm_top_ad_iframe',
'csm_top_ad_reflow',
'csm_top_ad_tagdeliver',
'csm_top_ad_request',
'csm_top_rhs_load',
'csm_top_rhs_iframe',
'csm_top_rhs_reflow',
'csm_top_rhs_tagdeliver',
'csm_top_rhs_request',
'top_ad.got_ad',
'top_rhs.got_ad',
'injected_billboard.got_ad',
'injected_navstrip.got_ad',
'bottom_ad.got_ad',
'top_ad.blank',
'top_rhs.blank',
'injected_billboard.blank',
'injected_navstrip.blank',
'bottom_ad.blank',
'top_ad.null',
'top_rhs.null',
'injected_billboard.null',
'injected_navstrip.null',
'bottom_ad.null',
'page_load'
]);
generic.monitoring.set_forester_info("main");
generic.monitoring.set_twilight_info(
"main", "GB", "3d68141e71003545e07c3fd51c2b1866fb441f29",
"2014-04-08T17%3A05%3A27GMT",
"http://s.media-imdb.com/twilight/?",
"consumer");
generic.send_csm_head_metrics && generic.send_csm_head_metrics();
generic.monitoring.start_timing("page_load");
generic.seconds_to_midnight = 50073;
generic.days_to_midnight = 0.5795485973358154;
ad_utils.set_slots_on_page({ 'injected_navstrip': 1, 'top_ad': 1, 'top_rhs': 1, 'bottom_ad': 1, 'injected_billboard': 1 });
consoleLog('advertising initialized', 'ads');
}, "ads js missing, skipping ads setup.");
```
--------------------------------
### Create and Post New JSON Object
Source: https://context7.com/fsprojects/fsharp.data/llms.txt
Defines a type from a JSON sample and constructs a new JSON object programmatically. Includes a commented-out example of posting the JSON.
```F#
// Creating JSON and posting it
[]
let IssueSample = "{"title":"bug","body":"desc","assignee":"","milestone":1,"labels":[]}"
type GitHubIssue = JsonProvider
let newIssue = GitHubIssue.Issue("Test issue", "Body text", assignee="", labels=[||], milestone=0)
// newIssue.JsonValue.Request "https://api.github.com/repos/owner/repo/issues"
```
--------------------------------
### Simple GET Request
Source: https://context7.com/fsprojects/fsharp.data/llms.txt
Performs a simple HTTP GET request and returns the response body as a string. No special setup is required.
```F#
open FSharp.Data
let html = Http.RequestString("http://tomasp.net")
```
--------------------------------
### Generate and Preview Documentation
Source: https://github.com/fsprojects/fsharp.data/blob/main/AGENTS.md
Generate the project documentation and preview it. This command is used to update and review the documentation before release.
```bash
dotnet run --project build/build.fsproj -t GenerateDocs
```
--------------------------------
### Run All Benchmarks
Source: https://github.com/fsprojects/fsharp.data/blob/main/tests/FSharp.Data.Benchmarks/README.md
Execute all available benchmarks in Release mode. This provides a comprehensive performance overview.
```bash
dotnet run -c Release
```
--------------------------------
### Build the FSharp.Data Solution
Source: https://github.com/fsprojects/fsharp.data/blob/main/AGENTS.md
Build the entire FSharp.Data solution. This command compiles all projects within the solution.
```bash
./build.sh
```
```bash
dotnet run --project build/build.fsproj -t Build
```
--------------------------------
### Build Project in Release Mode
Source: https://github.com/fsprojects/fsharp.data/blob/main/tests/FSharp.Data.Benchmarks/README.md
Build the project in Release mode before running benchmarks. This ensures optimal performance measurements.
```bash
dotnet build -c Release
```
--------------------------------
### Asynchronous HTTP Request
Source: https://context7.com/fsprojects/fsharp.data/llms.txt
Demonstrates making an asynchronous HTTP GET request using `AsyncRequestString`. This is suitable for non-blocking operations in F# applications.
```F#
open FSharp.Data
async {
let! page = Http.AsyncRequestString("http://tomasp.net")
printfn "Downloaded %d chars" page.Length
} |> Async.Start
```
--------------------------------
### Run All Build Tasks
Source: https://github.com/fsprojects/fsharp.data/blob/main/AGENTS.md
Perform all build-related tasks, including building, testing, generating documentation, and packing the project.
```bash
dotnet run --project build/build.fsproj -t All
```
--------------------------------
### jQuery Plugin for Embedding Players
Source: https://github.com/fsprojects/fsharp.data/blob/main/tests/FSharp.Data.Tests/Data/us_presidents_wikipedia.html
Extends jQuery to provide an 'embedPlayer' method. It handles player setup, dependency loading, and media processing.
```javascript
$.fn.embedPlayer=function(readyCallback){var playerSet=this;mw.log('jQuery.fn.embedPlayer :: '+$(this).length);var dependencySet=\['mw.EmbedPlayer' \\];var rewriteElementCount=0;$(this).each(function(inx,playerElement){var skinName='';$(playerElement).removeAttr('controls');if(!$.browser.mozilla){$(playerElement).parent().getAbsoluteOverlaySpinner().attr('id','loadingSpinner\_'+$(playerElement).attr('id'));}$(mw).trigger('EmbedPlayerUpdateDependencies',\\[playerElement,dependencySet\\]);});dependencySet=$.uniqueArray(dependencySet);mediaWiki.loader.using(dependencySet,function(){mw.processEmbedPlayers(playerSet,readyCallback);},function(e){throw new Error('Error loading EmbedPlayer dependency set: '+e.message);});};
```
--------------------------------
### Cookie Management Functions
Source: https://github.com/fsprojects/fsharp.data/blob/main/tests/FSharp.Data.Tests/Data/rottentomatoes.html
Provides functions to get, set, and delete cookies. The setCookie function supports expiration, path, domain, and secure flags.
```javascript
RT.getCookie = function(c) {
var d = document.cookie.indexOf(c + "=");
var a = d + c.length + 1;
if ((!d) && (c != document.cookie.substring(0, c.length))) {
return null
}
if (d == -1) {
return null
}
var b = document.cookie.indexOf(";", a);
if (b == -1) {
b = document.cookie.length
}
return unescape(document.cookie.substring(a, b))
};
window.getCookie = RT.getCookie;
```
```javascript
RT.setCookie = function(c, e, a, h, d, g) {
var b = new Date();
b.setTime(b.getTime());
if (a) {
a = a * 1000 * 60 * 60 * 24
}
var f = new Date(b.getTime() + (a));
document.cookie = c + "=" + encodeURIComponent(e) + ((a) ? ";expires=" + f.toGMTString() : "") + ((h) ? ";path=" + h : "") + ((d) ? ";domain=" + d : "") + ((g) ? ";secure" : "")
}
window.setCookie = RT.setCookie;
```
```javascript
RT.deleteCookie = function(a, c, b) {
if (getCookie(a)) {
document.cookie = a + "=" + ((c) ? ";path=" + c : "") + ((b) ? ";domain=" + b : "") + ";expires=Thu, 01-Jan-1970 00:00:01 GMT"
}
}
window.deleteCookie = RT.deleteCookie;
```
```javascript
RT.cookieHas = function(sKey) {
return (new RegExp("(?:^|;\\s\*)" + escape(sKey).replace(/[-\\.\+\*]/g, "\\$&") + "\\s\*\\=")).test(document.cookie);
}
```
--------------------------------
### XML Construction and Transformation
Source: https://context7.com/fsprojects/fsharp.data/llms.txt
Constructs new XML documents by transforming existing XML data. This example demonstrates creating an 'OrderLines' XML from an 'InputXml' structure.
```F#
[]
let InputSample = """"""
[]
let OutputSample = """"""
type InputXml = XmlProvider
type OutputXml = XmlProvider
let lines =
OutputXml.OrderLines
[| for c in InputXml.GetSample().Customers do
for o in c.Orders do
for l in o.OrderLines do
yield OutputXml.OrderLine(c.Name, o.Number, l.Item, l.Quantity) |]
```
--------------------------------
### Initialize eBay Context and Load Widgets
Source: https://github.com/fsprojects/fsharp.data/blob/main/tests/FSharp.Data.Tests/Data/ebay_cars.htm
Initializes the eBay context with site-specific settings and loads recommendation widgets. This script is typically executed on page load.
```javascript
var Context = raptor.require('ebay.context.Context');
Context.call(Context, { "site": 3, "errors": { "enabled": true }, "app": "raptor", "domain": ".ebay.co.uk", "pool": "production", "cobrand": 2, "locale": "en_GB", "features": {}, "pid": 2045573 });
if (pCon && !pCon.isDash) {
$.ajaxSetup({
beforeSend: function() {
(this.url.indexOf("?") === -1) ? this.url += '?_dash=0': this.url += '&_dash=0'
}
});
}
$rwidgets(['raptor.merch.MerchManager', 'w1-1', { "customCallbackHandler": false, "th": 1000, "pids": ["100033", "100034"], "merchRaptorEnabled": true, "loadJsAsync": true, "enableOnScroll": false, "url": "http:\/\/reco.ebay.com\/service\/plmt\/100033-100034?srchCtxt=%28dmLCat%3D9801%7CdmCats%3D9844%2C9837%2C9873%2C9858%2C9855%2C9844%2C9873%2C9837%2C9858%2C9855%7CsrtCnt%3D50%7CsrtType%3DBEST_MATCH%7CvType%3DLIST_VIEW%7CmCCatId%3D0%7CminPrice%3D0.0%7CmaxPrice%3D0.0%7CcrncyId%3D0%7CfShip%3D0%7Cetrs%3D0%29&itm=151274225847&si=3&ctg=9801&guid=424efa691450a5678f6d0556fffe3789&usrSi=UK&locale=en-GB&fmt=html&_qi=t6pwslg%60%3C%3Dpie3a57d.5%60%3Fe" }]);
new(raptor.require('raptor.tracking.core.Tracker'))({
"psi": "AT0u6AAE*",
"rover": {
"clk": "/roverclk/0/0/9",
"imp": "/roverimp/0/0/9",
"uri": "http://rover.ebay.co.uk"
},
"pid": "p2045573"
});
raptor.require('raptor.tracking.idmap.IdMap').roverService("http://rover.ebay.co.uk/idmap/0?footer");
```
--------------------------------
### Quick Dry Run for Testing
Source: https://github.com/fsprojects/fsharp.data/blob/main/tests/FSharp.Data.Benchmarks/README.md
Perform a quick dry run of a specific benchmark for testing purposes. This is useful for verifying benchmark setup without a full execution.
```bash
dotnet run -c Release -- --job dry --filter "*ParseSimpleJson*"
```