Movie Database

Calling REST API using Apiary.io

Searching The Movie Database with F#

Search movies

Found movies

×
 1: 
 2: 
 3: 
 4: 
 5: 
 6: 
 7: 
 8: 
 9: 
10: 
11: 
12: 
13: 
14: 
15: 
16: 
17: 
18: 
19: 
20: 
21: 
22: 
23: 
24: 
25: 
26: 
27: 
28: 
29: 
30: 
31: 
32: 
33: 
34: 
35: 
36: 
37: 
38: 
39: 
40: 
41: 
42: 
43: 
44: 
45: 
46: 
47: 
48: 
49: 
50: 
51: 
52: 
53: 
54: 
55: 
56: 
57: 
58: 
59: 
60: 
61: 
62: 
63: 
64: 
65: 
66: 
67: 
68: 
69: 
70: 
71: 
72: 
73: 
74: 
75: 
76: 
77: 
78: 
79: 
80: 
81: 
82: 
83: 
84: 
85: 
86: 
87: 
88: 
89: 
90: 
91: 
[<ReflectedDefinition>]
module Program

open FunScript
open FSharp.Data

// ------------------------------------------------------------------
// Initializataion

type MovieDb = ApiaryProvider<"themoviedb">

let jQuery(selector : string) = Globals.Dollar.Invoke selector
let (?) jq name = jq("#" + name)

// ------------------------------------------------------------------
// Main function

let main() = 

  let db = new MovieDb("http://api.themoviedb.org")
  db.AddQueryParam("api_key", "6ce0ef5b176501f8c07c634dfa933cff")
  let root = "http://cf2.imgobject.com/t/p/w92/"

  // ----------------------------------------------------------------
  // Show details

  let showDetails (id:int) = async {
    let! movie = db.Movie.AsyncGetMovie(id.ToString())
    jQuery?dialogOverview.text(movie.Overview) |> ignore 
    jQuery?dialogTitle.text(movie.Title) |> ignore
    jQuery?dialogImage.attr("src", root + movie.PosterPath) |> ignore
  
    let! casts = movie.AsyncCasts()
    let sorted = casts.Cast |> Array.sortBy (fun c -> c.Order)    
    let sorted = 
      if sorted.Length <= 10 then sorted |> Seq.ofArray 
      else sorted |> Seq.ofArray |> Seq.take 10

    jQuery?dialogCast.html("") |> ignore
    for cast in casts.Cast do 
      let html = "<strong>" + cast.Name + "</strong> (" + cast.Character + ")"
      let li = jQuery("<li>")
      li.html(html) |> ignore
      li.appendTo(jQuery?dialogCast) |> ignore }

  // ----------------------------------------------------------------
  // Movie search

  let search term = async {
    let! res = db.Search.AsyncMovie(query=["query", term])
    jQuery?results.html("") |> ignore

    res.Results 
    |> Seq.ofArray
    |> Seq.iteri (fun index item ->
        
        let link = 
          jQuery("<a>").attr("data-toggle", "modal").
            attr("href", "#detailsDialog").text(item.Title).
            click(fun e -> showDetails item.Id |> Async.StartImmediate; null)

        let details = jQuery("<ul>")
        let date = 
          match item.ReleaseDate.DateTime with
          | None -> "(not known)"
          | Some dt -> dt.ToString()
        jQuery("<li>").html("<strong>Released:</strong> " + date).
          appendTo(details) |> ignore
        jQuery("<li>").html("<strong>Average vote:</strong> " + item.VoteAverage.ToString()).
          appendTo(details) |> ignore
        jQuery("<li>").html("<strong>Popularity:</strong> " + item.Popularity.ToString()).
          appendTo(details) |> ignore

        let body = jQuery("<div>").addClass("searchResult")
        jQuery("<h3>").append([| box link |]).appendTo(body) |> ignore
        jQuery("<img>").attr("src", root + item.PosterPath).appendTo(body) |> ignore
        details.appendTo(body) |> ignore
        jQuery("<div>").addClass("clearer").appendTo(body) |> ignore
        body.appendTo(jQuery?results) |> ignore )}

  // ----------------------------------------------------------------
  // Movie search

  jQuery?searchButton.click(fun () ->
    let id = jQuery?searchInput._val() :?> string
    search id |> Async.StartImmediate )

// ------------------------------------------------------------------
let components =
  FunScript.Data.Components.DataProviders  
do Runtime.Run(components=components, directory="Web")
Multiple items
type ReflectedDefinitionAttribute =
  inherit Attribute
  new : unit -> ReflectedDefinitionAttribute

Full name: Microsoft.FSharp.Core.ReflectedDefinitionAttribute

--------------------
new : unit -> ReflectedDefinitionAttribute
module Program
namespace FunScript
namespace FSharp
namespace FSharp.Data
type MovieDb = ApiaryProvider<...>

Full name: Program.MovieDb
type ApiaryProvider

Full name: FSharp.Data.ApiaryProvider
val jQuery : selector:string -> JQuery

Full name: Program.jQuery
val selector : string
Multiple items
val string : value:'T -> string

Full name: Microsoft.FSharp.Core.Operators.string

--------------------
type string = System.String

Full name: Microsoft.FSharp.Core.string
type Globals

Full name: Globals
property Globals.Dollar: JQueryStatic
member JQueryStatic.Invoke : unit -> JQuery
member JQueryStatic.Invoke : element:Element -> JQuery
member JQueryStatic.Invoke : _object:AnonymousType814 -> JQuery
member JQueryStatic.Invoke : elementArray:Element array -> JQuery
member JQueryStatic.Invoke : _object:JQuery -> JQuery
member JQueryStatic.Invoke : func:Function -> JQuery
member JQueryStatic.Invoke : array:obj array -> JQuery
member JQueryStatic.Invoke : selector:string * ?context:obj -> JQuery
val jq : (string -> 'a)
val name : string
val main : unit -> JQuery

Full name: Program.main
val db : MovieDb
member RuntimeImplementation.Apiary.ApiaryContext.AddQueryParam : key:string * value:string -> unit
val root : string
val showDetails : (int -> Async<unit>)
val id : int
Multiple items
val int : value:'T -> int (requires member op_Explicit)

Full name: Microsoft.FSharp.Core.Operators.int

--------------------
type int = int32

Full name: Microsoft.FSharp.Core.int

--------------------
type int<'Measure> = int

Full name: Microsoft.FSharp.Core.int<_>
val async : AsyncBuilder

Full name: Microsoft.FSharp.Core.ExtraTopLevelOperators.async
val movie : ApiaryProvider<...>.DomainTypes.Entity7
property ApiaryProvider<...>.Movie: ApiaryProvider<...>.DomainTypes.MovieType
ApiaryProvider<...>.DomainTypes.MovieType.AsyncGetMovie(id: string, ?query: List<string * string>, ?headers: List<string * string>) : Async<ApiaryProvider<...>.DomainTypes.Entity7>


Get the basic movie information for a specific movie id.

 
 Required Parameters
 api_key
 Optional Parameters
 language ISO 639-1 code.
 append_to_response Comma separated, any movie method
System.Int32.ToString() : string
System.Int32.ToString(provider: System.IFormatProvider) : string
System.Int32.ToString(format: string) : string
System.Int32.ToString(format: string, provider: System.IFormatProvider) : string
property ApiaryProvider<...>.DomainTypes.Entity7.Overview: string
val ignore : value:'T -> unit

Full name: Microsoft.FSharp.Core.Operators.ignore
property ApiaryProvider<...>.DomainTypes.Entity7.Title: string
property ApiaryProvider<...>.DomainTypes.Entity7.PosterPath: string
val casts : ApiaryProvider<...>.DomainTypes.Entity14
ApiaryProvider<...>.DomainTypes.Entity7.AsyncCasts(?query: List<string * string>, ?headers: List<string * string>) : Async<ApiaryProvider<...>.DomainTypes.Entity14>


Get the cast information for a specific movie id.

 
 Required Parameters
 api_key
 Optional Parameters
 append_to_response Comma separated, any movie method
val sorted : ApiaryProvider<...>.DomainTypes.Entity15 []
property ApiaryProvider<...>.DomainTypes.Entity14.Cast: ApiaryProvider<...>.DomainTypes.Entity15 []
module Array

from Microsoft.FSharp.Collections
val sortBy : projection:('T -> 'Key) -> array:'T [] -> 'T [] (requires comparison)

Full name: Microsoft.FSharp.Collections.Array.sortBy
val c : ApiaryProvider<...>.DomainTypes.Entity15
property ApiaryProvider<...>.DomainTypes.Entity15.Order: int
val sorted : seq<ApiaryProvider<...>.DomainTypes.Entity15>
module Seq

from Microsoft.FSharp.Collections
val ofArray : source:'T [] -> seq<'T>

Full name: Microsoft.FSharp.Collections.Seq.ofArray
val take : count:int -> source:seq<'T> -> seq<'T>

Full name: Microsoft.FSharp.Collections.Seq.take
val cast : ApiaryProvider<...>.DomainTypes.Entity15
val html : string
property ApiaryProvider<...>.DomainTypes.Entity15.Name: string
property ApiaryProvider<...>.DomainTypes.Entity15.Character: string
val li : JQuery
member JQuery.html : unit -> string
member JQuery.html : htmlString:string -> JQuery
member JQuery.html : htmlContent:System.Func<float,string,string> -> JQuery
member JQuery.html : _obj:JQuery -> JQuery
member JQuery.appendTo : target:obj -> JQuery
val search : (string -> Async<unit>)
val term : string
val res : ApiaryProvider<...>.DomainTypes.Entity89
property ApiaryProvider<...>.Search: ApiaryProvider<...>.DomainTypes.SearchType
ApiaryProvider<...>.DomainTypes.SearchType.AsyncMovie(?query: List<string * string>, ?headers: List<string * string>) : Async<ApiaryProvider<...>.DomainTypes.Entity89>


Search for movies by title.

 
 Required Parameters
 api_key
 query CGI escaped string
 Optional Parameters
 page Minimum value is 1, expected value is an integer.
 language ISO 639-1 code.
 include_adult Toggle the inclusion of adult titles. Expected value is: true or false
 year Filter the results release dates to matches that include this value.
 primary_release_year Filter the results so that only the primary release dates have this value.
 search_type By default, the search type is 'phrase'. This is almost guaranteed the option you will want. It's a great all purpose search type and by far the most tuned for every day querying. For those wanting more of an "autocomplete" type search, set this option to 'ngram'.
val query : Linq.QueryBuilder

Full name: Microsoft.FSharp.Core.ExtraTopLevelOperators.query
property ApiaryProvider<...>.DomainTypes.Entity89.Results: ApiaryProvider<...>.DomainTypes.Entity90 []
val iteri : action:(int -> 'T -> unit) -> source:seq<'T> -> unit

Full name: Microsoft.FSharp.Collections.Seq.iteri
val index : int
val item : ApiaryProvider<...>.DomainTypes.Entity90
val link : JQuery
property ApiaryProvider<...>.DomainTypes.Entity90.Title: string
val e : JQueryEventObject
property ApiaryProvider<...>.DomainTypes.Entity90.Id: int
Multiple items
type Async
static member AsBeginEnd : computation:('Arg -> Async<'T>) -> ('Arg * AsyncCallback * obj -> IAsyncResult) * (IAsyncResult -> 'T) * (IAsyncResult -> unit)
static member AwaitEvent : event:IEvent<'Del,'T> * ?cancelAction:(unit -> unit) -> Async<'T> (requires delegate and 'Del :> Delegate)
static member AwaitIAsyncResult : iar:IAsyncResult * ?millisecondsTimeout:int -> Async<bool>
static member AwaitTask : task:Task<'T> -> Async<'T>
static member AwaitWaitHandle : waitHandle:WaitHandle * ?millisecondsTimeout:int -> Async<bool>
static member CancelDefaultToken : unit -> unit
static member Catch : computation:Async<'T> -> Async<Choice<'T,exn>>
static member FromBeginEnd : beginAction:(AsyncCallback * obj -> IAsyncResult) * endAction:(IAsyncResult -> 'T) * ?cancelAction:(unit -> unit) -> Async<'T>
static member FromBeginEnd : arg:'Arg1 * beginAction:('Arg1 * AsyncCallback * obj -> IAsyncResult) * endAction:(IAsyncResult -> 'T) * ?cancelAction:(unit -> unit) -> Async<'T>
static member FromBeginEnd : arg1:'Arg1 * arg2:'Arg2 * beginAction:('Arg1 * 'Arg2 * AsyncCallback * obj -> IAsyncResult) * endAction:(IAsyncResult -> 'T) * ?cancelAction:(unit -> unit) -> Async<'T>
static member FromBeginEnd : arg1:'Arg1 * arg2:'Arg2 * arg3:'Arg3 * beginAction:('Arg1 * 'Arg2 * 'Arg3 * AsyncCallback * obj -> IAsyncResult) * endAction:(IAsyncResult -> 'T) * ?cancelAction:(unit -> unit) -> Async<'T>
static member FromContinuations : callback:(('T -> unit) * (exn -> unit) * (OperationCanceledException -> unit) -> unit) -> Async<'T>
static member Ignore : computation:Async<'T> -> Async<unit>
static member OnCancel : interruption:(unit -> unit) -> Async<IDisposable>
static member Parallel : computations:seq<Async<'T>> -> Async<'T []>
static member RunSynchronously : computation:Async<'T> * ?timeout:int * ?cancellationToken:CancellationToken -> 'T
static member Sleep : millisecondsDueTime:int -> Async<unit>
static member Start : computation:Async<unit> * ?cancellationToken:CancellationToken -> unit
static member StartAsTask : computation:Async<'T> * ?taskCreationOptions:TaskCreationOptions * ?cancellationToken:CancellationToken -> Task<'T>
static member StartChild : computation:Async<'T> * ?millisecondsTimeout:int -> Async<Async<'T>>
static member StartChildAsTask : computation:Async<'T> * ?taskCreationOptions:TaskCreationOptions -> Async<Task<'T>>
static member StartImmediate : computation:Async<unit> * ?cancellationToken:CancellationToken -> unit
static member StartWithContinuations : computation:Async<'T> * continuation:('T -> unit) * exceptionContinuation:(exn -> unit) * cancellationContinuation:(OperationCanceledException -> unit) * ?cancellationToken:CancellationToken -> unit
static member SwitchToContext : syncContext:SynchronizationContext -> Async<unit>
static member SwitchToNewThread : unit -> Async<unit>
static member SwitchToThreadPool : unit -> Async<unit>
static member TryCancelled : computation:Async<'T> * compensation:(OperationCanceledException -> unit) -> Async<'T>
static member CancellationToken : Async<CancellationToken>
static member DefaultCancellationToken : CancellationToken

Full name: Microsoft.FSharp.Control.Async

--------------------
type Async<'T>

Full name: Microsoft.FSharp.Control.Async<_>
static member Async.StartImmediate : computation:Async<unit> * ?cancellationToken:System.Threading.CancellationToken -> unit
val details : JQuery
val date : string
property ApiaryProvider<...>.DomainTypes.Entity90.ReleaseDate: ApiaryProvider<...>.DomainTypes.Choice12
property ApiaryProvider<...>.DomainTypes.Choice12.DateTime: Option<System.DateTime>
union case Option.None: Option<'T>
union case Option.Some: 'T -> Option<'T>
val dt : System.DateTime
System.DateTime.ToString() : string
System.DateTime.ToString(provider: System.IFormatProvider) : string
System.DateTime.ToString(format: string) : string
System.DateTime.ToString(format: string, provider: System.IFormatProvider) : string
property ApiaryProvider<...>.DomainTypes.Entity90.VoteAverage: decimal
System.Decimal.ToString() : string
System.Decimal.ToString(provider: System.IFormatProvider) : string
System.Decimal.ToString(format: string) : string
System.Decimal.ToString(format: string, provider: System.IFormatProvider) : string
property ApiaryProvider<...>.DomainTypes.Entity90.Popularity: decimal
val body : JQuery
val box : value:'T -> obj

Full name: Microsoft.FSharp.Core.Operators.box
property ApiaryProvider<...>.DomainTypes.Entity90.PosterPath: string
val id : string
val components : InternalCompiler.CompilerComponent list

Full name: Program.components
namespace FunScript.Data
module Components

from FunScript.Data
val DataProviders : InternalCompiler.CompilerComponent list

Full name: FunScript.Data.Components.DataProviders

Live demo

Click here to open the sample live, running using JavaScript in a dialog window.

To look at the generated JavaScript, view the source of this web page and scroll to the end of the file.

Tutorials

Learn FunScript from the following introductory tutorials

Samples

Browse other amazing samples created with FunScript

Fork me on GitHub