blob: 525e5e55d9ab67f73d96f000fdf552441dab510d [file] [log] [blame]
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="content-type" content="text/html;charset=utf-8">
<title>Introduction to the Endpoints Proto Datastore API</title>
<link rel="stylesheet" href="/css/pycco.css">
</head>
<body>
<div id="background"></div>
<div id='container'>
<div class='section'>
<div class='docs'><h1>Introduction to the Endpoints Proto Datastore API</h1></div>
</div>
<div class='clearall'>
<div class='section' id='section-0'>
<div class='docs'>
<div class='octowrap'>
<a class='octothorpe' href='#section-0'>#</a>
</div>
<p>This library is intended to be used with the Python version of Google Cloud Endpoints.
If you'd like to learn more about Google Cloud Endpoints, please visit our
<a href="https://developers.google.com/appengine/docs/python/endpoints/">documentation</a>.
To run each of these samples, you should include the <code>endpoints_proto_datastore</code>
<a href="http://code.google.com/p/endpoints-proto-datastore/source/browse/#hg%2Fendpoints_proto_datastore">folder</a>
included with this project.</p>
</div>
</div>
<div class='clearall'>
<div class='section' id='section-1'>
<div class='docs'>
<div class='octowrap'>
<a class='octothorpe' href='#section-1'>#</a>
</div>
<p>The Endpoints Proto Datastore API provides an abstraction that allows
existing model classes to be used with Google Cloud Endpoints. By extending the
functionality provided by <code>ndb.Model</code> class and the <code>endpoints</code>
library, this library allows you to directly interact with model entities in your
API methods rather than ProtoRPC requests.</p>
</div>
<div class='code'>
<div class="highlight"><pre></pre></div>
</div>
</div>
<div class='clearall'>
<div class='section' id='section-2'>
<div class='docs'>
<div class='octowrap'>
<a class='octothorpe' href='#section-2'>#</a>
</div>
<p>For example, instead of:</p>
</div>
<div class='code'>
<div class="highlight"><pre> <span class="nd">@endpoints.method</span><span class="p">(</span><span class="n">MyModelMessage</span><span class="p">,</span> <span class="n">MyModelMessage</span><span class="p">,</span>
<span class="n">path</span><span class="o">=</span><span class="s">&#39;mymodel&#39;</span><span class="p">,</span> <span class="n">http_method</span><span class="o">=</span><span class="s">&#39;POST&#39;</span><span class="p">,</span>
<span class="n">name</span><span class="o">=</span><span class="s">&#39;mymodel.insert&#39;</span><span class="p">)</span>
<span class="k">def</span> <span class="nf">InsertModel</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">request</span><span class="p">):</span>
<span class="n">my_model</span> <span class="o">=</span> <span class="n">MyModel</span><span class="p">(</span><span class="n">attr1</span><span class="o">=</span><span class="n">request</span><span class="o">.</span><span class="n">attr1</span><span class="p">,</span> <span class="n">attr2</span><span class="o">=</span><span class="n">request</span><span class="o">.</span><span class="n">attr2</span><span class="p">, ...)</span>
<span class="n">transformed_model</span> <span class="o">=</span> <span class="n">DoSomething</span><span class="p">(</span><span class="n">my_model</span><span class="p">)</span>
<span class="k">return</span> <span class="n">MyModelMessage</span><span class="p">(</span><span class="n">attr1</span><span class="o">=</span><span class="n">transformed_model</span><span class="o">.</span><span class="n">attr1</span><span class="p">,</span>
<span class="n">attr2</span><span class="o">=</span><span class="n">transformed_model</span><span class="o">.</span><span class="n">attr2</span><span class="p">, ...)</span></pre></div>
</div>
</div>
<div class='clearall'>
<div class='section' id='section-3'>
<div class='docs'>
<div class='octowrap'>
<a class='octothorpe' href='#section-3'>#</a>
</div>
<p>we can directly use the entity in the request:</p>
</div>
<div class='code'>
<div class="highlight"><pre> <span class="nd">@MyModel.method</span><span class="p">(</span><span class="n">path</span><span class="o">=</span><span class="s">&#39;mymodel&#39;</span><span class="p">,</span> <span class="n">http_method</span><span class="o">=</span><span class="s">&#39;POST&#39;</span><span class="p">,</span>
<span class="n">name</span><span class="o">=</span><span class="s">&#39;mymodel.insert&#39;</span><span class="p">)</span>
<span class="k">def</span> <span class="nf">InsertModel</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">my_model</span><span class="p">):</span>
<span class="k">return</span> <span class="n">DoSomething</span><span class="p">(</span><span class="n">my_model</span><span class="p">)</span></pre></div>
</div>
</div>
<div class='clearall'>
<div class='section' id='section-4'>
<div class='docs'>
<div class='octowrap'>
<a class='octothorpe' href='#section-4'>#</a>
</div>
<p>without ever even having to define a ProtoRPC message class!</p>
</div>
<div class='code'><div class="highlight"><pre></pre></div></div>
</div>
<div class='clearall'>
<div class='section' id='section-5'>
<div class='docs'>
<div class='octowrap'>
<a class='octothorpe' href='#section-5'>#</a>
</div>
<p>The Endpoints Proto Datastore API currently supports only NDB classes.
Using the Endpoints Proto Datastore API, custom models and properties can be created
to specify exactly how data that is sent to and sent by APIs written with Google
Cloud Endpoints will be structured.</p>
</div>
</div>
<div class='clearall'></div>
<div class='section' id='section-6'>
<div class='docs'>
<div class='octowrap'>
<a class='octothorpe' href='#section-6'>#</a>
</div>
<p>Using a provided method, request and response message schemas can be
defined that allow automatic serialization and deserialization of Cloud
Endpoints API payloads into model entities. In another provided method, the
same can be done to serialize and deserialize into model query objects.</p>
</div>
</div>
<div class='clearall'></div>
<div class='section' id='section-7'>
<div class='docs'>
<div class='octowrap'>
<a class='octothorpe' href='#section-7'>#</a>
</div>
<p>Through the samples provided in this sample, a reference is defined,
building up from the simplest use case to the most complex.</p>
</div>
</div>
<div class='clearall'></div>
<div class='section' id='section-8'>
<div class='docs'>
<div class='octowrap'>
<a class='octothorpe' href='#section-8'>#</a>
</div>
<p>Please check out the <a href="http://code.google.com/p/endpoints-proto-datastore/source/browse/">source</a> code,
and file any <a href="http://code.google.com/p/endpoints-proto-datastore/issues/list">issues or requests</a>
you have.</p>
</div>
</div>
<div class='clearall'></div>
<div class='section' id='section-9'>
<div class='docs'>
<div class='octowrap'>
<a class='octothorpe' href='#section-9'>#</a>
</div>
<p>To get started, check out our samples:
<ul>
<li><a href="/examples/basic.html">basic</a></li>
<li><a href="/examples/basic_with_auth.html">basic_with_auth</a></li>
<li><a href="/examples/paging.html">paging</a></li>
<li><a href="/examples/property_filters.html">property_filters</a></li>
<li><a href="/examples/custom_api_response_messages.html">custom_api_response_messages</a></li>
<li><a href="/examples/simple_get.html">simple_get</a></li>
<li><a href="/examples/matching_queries_to_indexes.html">matching_queries_to_indexes</a></li>
<li><a href="/examples/custom_alias_properties.html">custom_alias_properties</a></li>
<li><a href="/examples/keys_with_ancestors.html">keys_with_ancestors</a></li>
</ul>
</p>
</div>
</div>
<div class='clearall'></div>
</div>
</body>