none
How to create first rest client in Visual Studio 2017 RRS feed

  • Question

  • Hi! I have to create one button form to get information from rest api of Sharepoint 2013. For example, call this api-function

    /_api/web/lists(guid'zzz')/items. 

    using (SPWeb web = siteCollection.AllWebs["webname"])

    All problems is I have installed Visual Studio on my PC (not on server, where located Sharepoint).

    And i don't know how to make this. Is there any tutorials or video how to create first rest client

    for beginners in Visual Studio?

    Thursday, April 27, 2017 12:17 PM

All replies

  • Hi,

    SPWeb is server side object model, and we can only use this object in FARM solution(sandbox has deprecated), usually we not use REST api in FARM solution as server side object model object could do more operations instead of REST api.

    Rest api supposed to use for client side solution-SharePoint add-in mostly, or you could use it to custom SharePoint page/list forms etc.

    Here is a simple example for how to use it:

    Create a wiki page by site settings->add a page.

    Click edit page->insert->script editor

    Add below script to it, it’s just a sample to get the list items count and alert.

     <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.min.js"></script>
        <script type="text/javascript">
        $(function () {
            $("#btnClick").click(function () {
                var requestUri = _spPageContextInfo.webAbsoluteUrl + "/_api/web/lists/getByTitle('Employee')/items";
                $.ajax({
                    url: requestUri,
                    type: "GET",         
                    headers: {
                        "Accept": "application/json;odata=verbose",                    
                    },
                    success: onSuccess,
                    error: onError
                });
                function onSuccess(data) {
                    //get the list items
                    alert(data.d.results.length);
                }
                function onError(error) {
                    alert(JSON.stringify(error));
                }
            });
        });
        </script>
        <input id="btnClick" type="button" value="button" />

    I would suggest go through below thread, it would help you understand SharePoint available API and choose proper one based on your requirements.

    https://msdn.microsoft.com/en-us/library/office/jj164060.aspx

    One more tip, you could view REST API results(get request) from browser directly.

    For example:

    Best Regards,

    Lee


    Please remember to mark the replies as answers if they help.
    If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com


    Friday, April 28, 2017 3:54 AM
  • Hi,

    I am checking to see how things are going there on this issue. Please let us know if you would like further assistance.

    You can mark the helpful post as answer to help other community members find the helpful information quickly.

    You can also share your own solution here and mark it as answer, and we can learn from each other.

    Best Regards,

    Lee


    Please remember to mark the replies as answers if they help.
    If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com

    Monday, May 15, 2017 12:05 PM