I am trying to create some endpoints for my app engine application using endpoints_proto_datastore it works because the urls return something but just not what I expected.
Here is the code I have I know some of the imports are not needed but they are temporary
Model File
import endpoints
from google.appengine.ext import db
import webapp2
from endpoints_proto_datastore.ndb import EndpointsModel
class Estate(EndpointsModel):
hicid = db.IntegerProperty()
name = db.StringProperty()
address= db.PostalAddressProperty()
contact_phone = db.PhoneNumberProperty()
contact_name = db.StringProperty()
contact_email = db.EmailProperty()
location = db.GeoPtProperty()
created = db.DateTimeProperty(auto_now_add=True)
updated = db.DateTimeProperty(auto_now=True)
API file
import endpoints
from google.appengine.ext import ndb
from protorpc import remote
from endpoints_proto_datastore.ndb import EndpointsModel
from models.estate import *
@endpoints.api(name = 'raceManagerAPI', version = 'v1', description = 'An api for access to important data')
class raceManagerAPI(remote.Service):
@Estate.query_method(path = 'estates', name = 'estate.list')
def EstateList(self, query):
return query
app.yaml file
application: yellow-fox
version: 1
runtime: python27
api_version: 1
threadsafe: yes
handlers:
- url: /assets
static_dir: assets
- url: /signup
script: main.app
secure: always
- url: /login
script: main.app
secure: always
- url: /forgot
script: main.app
secure: always
# Endpoints Api
- url: /_ah/spi/.*
script: main.application
- url: .*
script: main.app
libraries:
- name: webapp2
version: "2.5.1"
- name: jinja2
version: latest
- name: endpoints
version: latest
main.py file has this in
application = endpoints.api_server([raceManagerAPI], restricted=False)
and this is what I get back from the api explorer
{
"kind": "raceManagerAPI#estateItem",
"etag": "\"hx0GGGqNWMq76QilvaW15fvq6DI/taVVBKufuJZtJ6w1S7kF6sHCh4M\""
}
What i was expecting was a list of items can someone tell me where I am going wrong the documentation don't give me much of an idea.
I believe your problem comes from using the old style db
here:
from google.appengine.ext import db
and in the various properties of Estate
, such as:
name = db.StringProperty()
Rather, you must use the new style ndb
, changing those two lines respectively to:
from google.appengine.ext import ndb
and:
name = ndb.StringProperty()
Now, in ndb
you won't find PostalAddressProperty
&c, so you'll need to fix those. But, the general idea is: always ever use ndb
, not db
.