Web

Web

Reference the library

// JavaScript
var $REST = require("gd-sprest");

// TypeScript
import { ContextInfo, Web } from "gd-sprest";

Get the current web

// Get the web
$REST.Web()
    // Execute the request
    .execute(function(web) {
        // Code goes here
    });

// Get the web
Web()
    // Execute the request
    .execute(web => {
        // Code goes here
    });

Get the root web

// Get the root web
$REST.Web($REST.ContextInfo.siteServerRelativeUrl)
    // Execute the request
    .execute(function(web) {
        // Code goes here
    });

// Get the root web
Web(ContextInfo.siteServerRelativeUrl)
    // Execute the request
    .execute(web => {
        // Code goes here
    });

Query the root web, expanding the fields and content types

// Get the root web
$REST.Web($REST.ContextInfo.siteServerRelativeUrl)
    // Expand the content types and fields
    .query({
        Expand: ["ContentTypes", "Fields"]
    })
    // Execute the request
    .execute(function(web) {
        var contentTypes = web.ContentTypes.results;
        var fields = web.Fields.results;

        // Code goes here
    });

// Get the root web
Web(ContextInfo.siteServerRelativeUrl)
    // Expand the content types and fields
    .query({
        Expand: ["ContentTypes", "Fields"]
    })
    // Execute the request
    .execute(web => {
        let contentTypes = web.ContentTypes.results;
        let fields = web.Fields.results;

        // Code goes here
    });